코딩92 LeetCode. Binary Tree Level Order Traversal [Trees] Problem: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], -Summary- Solve by BFS (Breadth-First Search) Algorithm using queue 1. Create a queue and keep adding the value if left or right subtree exists 2. While adding the value to the queue, we pop and add the value to the.. 2020. 6. 7. LeetCode. Symmetric Tree [Trees] Problem: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: But the following [1,2,2,null,3,null,3] is not: -Summary- 1. If a tree has no root or root itself exist, it will always return True 2. Otherwise, we keep check below condition recursively of the Tree's left and right subtree - leftSub.. 2020. 6. 7. LeetCode. Validate Binary Search Tree [Trees] Problem: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. -Summary- 1. Create a helper function to r.. 2020. 6. 6. LeetCode. Maximum Depth of Binary Tree [Trees] Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7], return its depth = 3. -Summary- Solve recursively 1. Find the maximum length of depth by comparing the left and right subtree. 2. Add 1 .. 2020. 6. 5. LeetCode. Linked List Cycle [Linked List] Problem: Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list. Example 1: Input: head = [3,2,0,-4], pos = 1 Output: true Explanation: There is a cycle in the linked list, where tail con.. 2020. 6. 4. LeetCode. Palindrome Linked List [Linked List] Problem: Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true -Summary- 1. Find a middle node using two-pointer in the original Linked list. (Fast and Slow) 2. Create a reverse_node and reverse the second half of the original Linked List 3. Compare 1st and 2nd half of the Linked list, if everything matches ret.. 2020. 6. 4. 이전 1 ··· 3 4 5 6 7 8 9 ··· 16 다음