当前位置:网站首页>【無標題】
【無標題】
2022-06-10 05:03:00 【程序媛JD】



c++:
/* // Definition for a Node. class Node { public: int val; Node* next; Node* random; Node(int _val) { val = _val; next = NULL; random = NULL; } }; */
class Solution {
public:
unordered_map<Node*,Node*>cachedNode;
Node* copyRandomList(Node* head) {
if(head == nullptr){
return head;
}
if(!cachedNode.count(head)){
Node* headNew = new Node(head->val);
cachedNode[head] = headNew;
headNew->next = copyRandomList(head->next);//遞歸
headNew->random = copyRandomList(head->random);//遞歸
}
return cachedNode[head];
}
};
go:
/** * Definition for a Node. * type Node struct { * Val int * Next *Node * Random *Node * } */
var cachedNode map[*Node]*Node
func deepCopy(head *Node) *Node {
if head == nil{
return nil
}
if n,has := cachedNode[head];has{
return n;
}
newNode := &Node{
Val:head.Val}
cachedNode[head] = newNode
newNode.Next = deepCopy(head.Next)
newNode.Random = deepCopy(head.Random)
return cachedNode[head]
}
func copyRandomList(head *Node) *Node {
cachedNode = map[*Node]*Node{
}
return deepCopy(head)
}

边栏推荐
- 使用MindSpore在GPU-PYNATIVE/ CPU-GRAPH_MODE 与 GPU-GRAPH_MODE 执行不一致
- JS wechat games - fighting mosquitoes
- How to use API interface of national weather forecast for rapid development
- 2022 refrigeration and air conditioning equipment operation special operation certificate examination question bank simulated examination platform operation
- Custom tooltips prompt bubble JS plug-in
- Wechat mobile JS small game stepping on the box source code
- Distributed loading model and incremental training on shengteng 910
- 2022 examination questions and online simulation examination for main principals of hazardous chemical business units
- torch.randn迁移成mindspore.ops.TruncatedNormal使用问题
- pytorch的add_module(name,module)用mindspore怎么表示
猜你喜欢

Personnaliser le plug - in bulles JS prompt tooltips
![[innovative document technology solution] Shanghai daoning provides you with a product - litera, which covers the entire document drafting life cycle, to help users create higher quality documents](/img/7e/a0d1b75a57f9e4e94ccdac5244d30c.png)
[innovative document technology solution] Shanghai daoning provides you with a product - litera, which covers the entire document drafting life cycle, to help users create higher quality documents

【UE4自动地形材质】

Installing mindinsight in the mindspire official website container does not work locally

Record the realization of animation effect on the page of small rocket of BiliBili (station B)

加快Kettle插入速度的小技巧

自定义Tooltips提示气泡Js插件
![mindspore训练阶段报错:Not find op[Add] in akg](/img/df/5ccc43e0d115b487dc3a38129bc88b.png)
mindspore训练阶段报错:Not find op[Add] in akg

S系列·修改文件的时间属性

Softing为艾默生提供AMS设备管理系统的连接解决方案
随机推荐
IIS下apk文件下载,需要配置MIMI类型,否则无法下载
S series · add legend in the made Matplotlib diagram
S series · add data to the text file without adding duplicate values
Apispace sunrise sunset API interface is free and easy to use
2022.5.25-----leetcode. four hundred and sixty-seven
Study notes for typescript
APISpace 日出日落API接口 免费好用
JS electronic alarm clock web page JS special effect code
2022 mobile crane driver examination questions and online simulation examination
Nx logo from brushing to switching on
2022 refrigeration and air conditioning equipment operation special operation certificate examination question bank simulated examination platform operation
2022.6.8-----leetcode. one thousand and thirty-seven
City / school / major, which is the most important when choosing a university| Daily anecdotes
Review of major events | quick view of important developments of eolink in May!
[innovative document technology solution] Shanghai daoning provides you with a product - litera, which covers the entire document drafting life cycle, to help users create higher quality documents
Softing为艾默生提供AMS设备管理系统的连接解决方案
Personnaliser le plug - in bulles JS prompt tooltips
APISpace 尾号限行API接口 免费好用
Interview question 08.07 Permutation without duplicate strings
25. Bom Event