
리트코드 - 226. Invert Binary Tree 출처 - https://leetcode.com/problems/invert-binary-tree/description/?envType=study-plan-v2&envId=top-interview-150 문제 설명 이진 트리의 루트가 주어지면 트리를 반전하고 루트를 반환합니다. 의사코드 함수 invertTree if (root == null) null 리턴 if (root.left != null) if (root.right == null) root.right = root.left root.left = null else TreeNode tempNode = new TreeNode tempNode = root.left root.left = root.righ..

리트코드 - 100. Same Tree 출처 - https://leetcode.com/problems/same-tree/description/?envType=study-plan-v2&envId=top-interview-150 문제 설명 두 이진 트리 p와 q의 루트가 주어지면 이들이 동일한지 확인하는 함수를 작성하세요. 두 개의 이진 트리가 구조적으로 동일하고 노드의 값이 동일한 경우 동일한 것으로 간주됩니다. 의사코드 함수 isSameTree if (p == null && q == null) return true else if (p == null || q == null) return false if (p.val == q.val) return isSameTree(p.left, q.left) && isSa..

리트코드 - 104. Maximum Depth of Binary Tree 출처 - https://leetcode.com/problems/maximum-depth-of-binary-tree/description/?envType=study-plan-v2&envId=top-interview-150 문제 설명 이진 트리의 root가 주어지면 최대 깊이를 반환합니다. 이진 트리의 최대 깊이는 root 노드에서 가장 먼 leaf 노드까지 가장 긴 경로를 따라 있는 노드 수입니다. 의사코드 함수 maxDepth if (root == null) return 0 Math.max(maxDepth(root.left), maxDepth(root.right)) + 1 리턴 함수끝 풀이코드 class Solution { publ..

리트코드 - 21. Merge Two Sorted Lists 출처 - https://leetcode.com/problems/merge-two-sorted-lists/description/?envType=study-plan-v2&envId=top-interview-150 문제 설명 두 개의 정렬된 연결 리스트인 list1과 list2의 헤드 노드가 주어집니다. 두 리스트를 하나의 정렬된 리스트로 병합합니다. 이 리스트는 첫 번째 두 리스트의 노드를 연결하여 만들어져야 합니다. 병합된 연결 리스트의 헤드를 반환합니다. 의사코드 dummyHead = new ListNode(0) currentNode = dummyHead 반복문 시작 (list1 != null && list2 != null) if (list1...

리트코드 - 20. Valid Parentheses 출처 - https://leetcode.com/problems/valid-parentheses/description/?envType=study-plan-v2&envId=top-interview-150 문제 설명 주어진 문자열 s가 단순히 문자 '(', ')', '{', '}', '[', ']'만을 포함하고 있는 경우, 입력 문자열이 유효한지를 확인합니다. 유효한 입력 문자열의 조건은 다음과 같습니다: 여는 괄호는 동일한 종류의 괄호로 닫혀야 합니다. 여는 괄호는 올바른 순서로 닫혀야 합니다. 각 닫는 괄호는 동일한 종류의 여는 괄호와 대응되어야 합니다. 의사코드 stack = new stack char[] arr = s를 char array로 변경 반복..

리트코드 - 228. Summary Ranges 출처 - https://leetcode.com/problems/summary-ranges/description/?envType=study-plan-v2&envId=top-interview-150 문제 설명 주어진 것은 정렬된 고유한 정수 배열 nums입니다. 범위 [a, b]는 a부터 b까지의 모든 정수 집합입니다(a,b포함). 배열 내의 모든 숫자를 정확히 포함하는 가장 작은 정렬된 범위 목록을 반환하십시오. 즉, nums의 각 요소가 정확히 하나의 범위에 포함되며, 하나의 범위에 속하지만 nums에는 없는 정수 x가 없어야 합니다. 목록 내의 각 범위 [a, b]는 다음과 같이 출력되어야 합니다: "a->b" if a != b "a" if a == b ..