리트코드(2)
-
리트코드 Recover Binary Search Tree 코드 및 해설 (파이썬)
https://leetcode.com/problems/recover-binary-search-tree/ Recover Binary Search Tree - LeetCode 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 올바른 BST라면 inorder 순회를 했을 때 값들이 오름차순으로 정렬되어야 한다는 사실을 이용해 풀이했습니다. inorder 순회를 하면서 result에 값을 저장하고, 오름차순 정렬이 되지 않는 부분들의 노드를 발견하면 swap에 추가적으로 저장했습니다. 순..
2021.06.27 -
리트코드 Populating Next Right Pointers in Each Node 코드 및 해설 (파이썬)
https://leetcode.com/problems/populating-next-right-pointers-in-each-node/description/ Populating Next Right Pointers in Each Node - LeetCode 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 BFS를 이용해 풀이했습니다. 먼저 root와 root의 depth인 1을 각각 다른 queue에 넣어주고 queue가 빌 때까지 다음을 반복합니다. 각 queue의 맨 첫번째 요소..
2021.06.23