leetcode 日经贴,Cpp code -Clone Graph
来源:互联网 发布:淘宝小孩的皮裤 编辑:程序博客网 时间:2024/06/07 09:35
Clone Graph
/** * Definition for undirected graph. * struct UndirectedGraphNode { * int label; * vector<UndirectedGraphNode *> neighbors; * UndirectedGraphNode(int x) : label(x) {}; * }; */class Solution {public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) { if (!node) { return NULL; } map<UndirectedGraphNode*, UndirectedGraphNode*> mp; queue<UndirectedGraphNode*> q; mp[node] = new UndirectedGraphNode(node->label); q.push(node); while (!q.empty()) { UndirectedGraphNode *cp = q.front(); UndirectedGraphNode *np = mp[cp]; q.pop(); for (int i = 0; i < cp->neighbors.size(); ++i) { UndirectedGraphNode *tp = cp->neighbors[i]; if (mp.find(tp) == mp.end()) { mp[tp] = new UndirectedGraphNode(tp->label); q.push(tp); } np->neighbors.push_back(mp[tp]); } } return mp[node]; }};
0 0
- leetcode 日经贴,Cpp code -Clone Graph
- Leetcode 133. Clone Graph (Medium) (cpp)
- LeetCode[Graph]: Clone Graph
- CODE 130: Clone Graph
- clone-graph Java code
- [LeetCode] CLone Graph
- LeetCode:Clone Graph
- [leetcode]Clone Graph
- Leetcode: Clone Graph
- [LeetCode] Clone Graph
- LeetCode题解:Clone Graph
- [LeetCode]Clone Graph
- leetcode Clone Graph
- leetcode-Clone Graph
- LeetCode | Clone Graph
- Leetcode: Clone Graph
- [LeetCode] Clone Graph
- LeetCode OJ:Clone Graph
- xa database resource 与non-xa database resoure的区别
- iOS, corelocation定位经纬度坐标,以及经纬度距离
- [Python--]Python Profilers 性能分析
- 被废弃的dispatch_get_current_queue
- Oracle格式化函数 to_char,to_date,to_number
- leetcode 日经贴,Cpp code -Clone Graph
- 木板墙问题
- 【原创】独家报道冷链行业新能量黑狗生鲜宅配
- 当你在浏览器地址栏输入一个URL后回车,将会发生的事情?
- c#抽象类和接口
- Adb connection Error / adb server is out of date.killing的解决办法
- Oracle 11g中recyclebin已经是静态参数,在线不能修改
- 理解RegisterClass
- request_region与release_region