1. 문제 개요
문제 링크 : 133. Clone Graph
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
- 그래프 기능 구현
2. 문제 풀이
그래프 기능을을 구현하면되는 간단한 문제입니다. 그래프에대한 이해도가 중요합니다.
LeetCode 요구 양식으로 코드 구현
var cloneGraph = function (node, clonedNodes = new Map()) {
if (!node) return null;
if (clonedNodes.has(node)) return clonedNodes.get(node);
const clonedNode = new Node(node.val);
clonedNodes.set(node, clonedNode);
for (const neighbor of node.neighbors) {
const clonedNeighbor = cloneGraph(neighbor, clonedNodes);
clonedNode.neighbors.push(clonedNeighbor);
}
return clonedNode;
};
LeetCode 제출 결과
이렇게 구현에 성공하였습니다.
3. 시간 복잡도 계산
더보기
O(nlogn) = O(nlogn)
4. 깃허브
관련 사항은 깃허브에 모두 기재되어 있습니다.
'LeetCode - Top Interview 150' 카테고리의 다른 글
[Java Script] 909. Snakes and Ladders (1) | 2023.09.15 |
---|---|
[Java Script] 373. Find K Pairs with Smallest Sums (0) | 2023.09.11 |
[Java Script] 215. Kth Largest Element in an Array (0) | 2023.09.11 |
[Java Script] 212. Word Search II (0) | 2023.09.11 |
[Java Script] 211. Design Add and Search Words Data Structure (0) | 2023.09.11 |