LeetCode ๐Ÿ”๏ธ

LeetCode ๐Ÿ”๏ธ/Tree

102. Binary Tree Level Order Traversal

Description: This question asked us to get 2 dimensional array which includes the value and level of tree. "3" is the only value of first level of tree. 9, 20 are the second level. 15, 7 are the third level. Each level is in the same list, we can see the different list in the output list. Solution: First, the solution used the queue method in collections library. "res" is what we are gonna retur..

LeetCode ๐Ÿ”๏ธ/Tree

124. Binary Tree Maximum Path

This is the Leetcode question called "Binary Tree Maximum Path): Every nodes have a specific value. Some are positive and some are negative. We can start from any node of tree. When we start, we can make a direction to other node. Solution: First, we make the list name "res" to return the sum. The function "dfs" is used for recurssion and return the value of the maximum case when we go thorugh t..

LeetCode ๐Ÿ”๏ธ/Tree

226. Invert Binary Tree

Description: So, we should change the right value of the root to the left value of the root. Solution: First, we have a condition: if the tree is empty, we just return root. I made the variable name "left", "right" which is pointer the right and the left value of the root. We change the value of right to the left, the left to the right through recurrsion. Finally, return the root.

LeetCode ๐Ÿ”๏ธ/Tree

100. Same Tree

Description: In this problem, we are gonna check the identical structure and their values. Two tree must the same tree structurely. Solution: * First condition checks "both p and q are None." If it is return True. * Second condition checks "one of p and q are None." If it is, then return False. --> The reason is that just one of p or q done, that menas both tree don't have identical structure. *..

LeetCode ๐Ÿ”๏ธ/Tree

104. Maximum Depth of Binary Tree

Description: We are trying to get a depth of binary tree. In example 1, weshould return "3", and example 2 should return "2." Solution1(Recursion): This is the method using recursive. We are going down to tree, adding 1 until the depth of tree. Since the recursive function have both value l and r, we should compare which is the longer. That's why we use the max(r, l) to compare which is the dept..

LeetCode ๐Ÿ”๏ธ/Matrix

79. Word Search

Description: We should go through every single matrix using Brute Force, backtracking, backtracking with recursively. Solution: We should go through the whole matrix. It is gonna be brute force search. This method makes the function dfs to make a path to search whole matrix. We have a materials length of Matrix(M, N), and the set of path to store our path in the matrix. Let's see the dfs functio..

LeetCode ๐Ÿ”๏ธ/Matrix

48. Rotate Image

Description: As we read the description of problem, we can't make another matrix for output. That means we can change the image without making matrix. Solution: We set left+=1 and right-=1, but it is out of for loop!, so that means we should change the left and top in person. The "i" means that how much apart from the beginning or the end of matrix. In example 1, after we change the value by the..

LeetCode ๐Ÿ”๏ธ/Matrix

54. Spiral Matrix

Decription: We are gonna make the variable name "Top, bottom, right_col, left_col to point the row and column you are currently in. Solution: We set the top and bottom to point to the first row and the last row. Next, we set left_column and right_column to point to the first column and the last column. We can see the sprial matrix gets value following this order: top row --> right most column --..

LeetCode ๐Ÿ”๏ธ/Matrix

73. Set Matrix Zeroes

Description: In the m * n matrix, there are serveral values. If the value is 0, than we should change the entire row value and column value as "0". Before we do actual coding, let's think about the solution we can easily think. If we should check the entire matrix by brute force or whatever. It's gonna have O(mn) time solution. If we make another matrix, and revise the value, then it is gonna ha..

LeetCode ๐Ÿ”๏ธ/Array

238. Product of Array Except Self

Description: If we are in nums[0], then output should be the product of all variables in array except nums[0]. I used the division operation, but the problem ask me to avoid using division operation. In addtion, the time complexity should be less than O(N), and space complexity is O(1). Solution1(not answer): We can use brute force here, but doesn't work for the problem. The reason is that time ..

KB0129
'LeetCode ๐Ÿ”๏ธ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (7 Page)