iT邦幫忙

2025 iThome 鐵人賽

1

https://ithelp.ithome.com.tw/upload/images/20260510/20177944ZFcyT2pAEW.jpg

https://ithelp.ithome.com.tw/upload/images/20260510/2017794433IXzACLdf.jpg

https://ithelp.ithome.com.tw/upload/images/20260510/20177944rKHszVTHCw.jpg

https://ithelp.ithome.com.tw/upload/images/20260510/20177944jNev5W7V9C.jpg

class Solution { // O(V + E), O(V)
public:
    unordered_map<Node*, Node*> mp;
    Node* cloneGraph(Node* onode) {
        if (!onode) return nullptr;
        if (mp.count(onode)) return mp[onode];
        Node* ncopy = new Node(onode->val);
        mp[onode] = ncopy;
        for (Node* nei : onode->neighbors)
            ncopy->neighbors.push_back(cloneGraph(nei));
        return ncopy;
    }
};

上一篇
跟上一題很像啦 好好輸出1091要趕快出門去看排球比賽囉:)
下一篇
母親節快樂 應該要一次改好:‘( 210
系列文
轉職仔之Data Science and ai master後的持續精進技術之路42
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言