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..
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..
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.
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. *..
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..
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..
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..
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 --..
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..
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 ..