LeetCode ๐Ÿ”๏ธ

LeetCode ๐Ÿ”๏ธ/Binary

338. Counting Bits

Today, I solved Counting Bits. Description: In this problem, we are gonna return the array. The array length should ne "n+1", and the array show how many 1 bits each number has in their binary number. Solution: The length of dp array: [0] * (n + 1) offset = 1 (This tells where the numbers between 2 ^n-1, 2^n) we are gonna check the offset reach out 1, 2, 4, 8 ... each time in for loop. 0 -> 0000..

LeetCode ๐Ÿ”๏ธ/Binary

191. Number of 1 Bits

Today, I solved the Number of 1 Bits from Leetcode. Description: In this question, we are gonna work on changing the binary number to decimal numbers. There are two methods to solve this problem in Python: Solution1: The first solution, we are gonna divide the number to see the first bit is 1 or 0. For example, 17 is 10001. 10001 % 2 = 1 Now, keep moving to the right! 1000 % 2 = 0 100 % 2 = 0 10..

LeetCode ๐Ÿ”๏ธ/Binary

371. Sum of Two Integers

Today I soled the "Sum of Two Integers" Description: This question ask us how to get sum of the two integers without using sign "+" and "-." In example 2, a is 2 => 10 b is 3 => 11 a+b: 10 + 11 ----- 101 (which is 5) In binary number, 1 + 1 makes the carry "1" to the next slot. For carry "1", we are gonna use & a & b: 10 & 11 ----- 100(so move to left

LeetCode ๐Ÿ”๏ธ/Linked List

23. Merge k Sorted Lists

Today, I solved the Merge K sorted Lists. Description: In this question, we are gonna merge several lists. And, the merged list should be sorted in order. Solution: This is the first part of solution. We will look into mergeLists() function later. If the gived lists are empty, we return None. While loop runs until the length of lists is over 1. We make the list for storing merged lists. Since we..

LeetCode ๐Ÿ”๏ธ/Linked List

141. Linked List Cycle

Today, I did the question: Linked List Cycle. Description: We should check whether cycle exist or not. head and pos is given. We can check the pos that which position is cycled back on the list. In example 1, 1st node is the returning node on the list. Then, how do we check the cycle on the list? The solution is similar to previous linked list question: We are gonna make the slow and fast pointe..

LeetCode ๐Ÿ”๏ธ/Linked List

143. Reorder List

Today, I solved "Reorder List." Description: It is hard to understand, but we are gonna reorder the list with rule. We can easily find the rule of the form: Before: L0 -> L1 -> L2 -> L3 -> L4 After: L0 -> L4 -> L1 -> L3 -> L2 Now, how can we change the list order without changing the value? We should make the other list to re-order the list. The recommendation is seperating the list as two lists..

LeetCode ๐Ÿ”๏ธ/Linked List

19. Remove Nth Node From End of List

Today, I solved "Remove Nth Node From End of List." Description: In this problem, we are gonna delete nth node from the end of the list. For example of case 1, we found the "4" is the 2nd node from the end of the list. But how can we delete and how can we know nth node from the end? Solution: 1. First, we are gonna make two pointers on the list: left and right. 2. "right" is "n" ahead of left. F..

LeetCode ๐Ÿ”๏ธ/Linked List

21. Merge Two Sorted Lists

Today, I solved the Merge Two Sorted Lists. Description: We have two lists, and we are gonna merge those two lists. The point is that we are gonna sort new list in non-decreasing order. Solution1: We make dummy node to avoid some error. And, we make curr node to know our location in both lists. Our while loop runs until we put every values in list1 and list2. If the value of list1 is less than l..

LeetCode ๐Ÿ”๏ธ/Linked List

206. Reverse Linked List

Today, I solved the Reverse Linked List. Description: In this problem, we reverse the order of single linked list. My idea was that changing the pointer to make reverse order. So, I thought I should change like this "1->2" as a "2->1" repeatedly. In the description of the question, we can see "A linked list can be reversed either iteratively or recursively." I'm not sure about this kind of quest..

LeetCode ๐Ÿ”๏ธ/Tree

572. Subtree of Another Tree

Description: This question is to know whether subRoot is in root or not. If the subRoot is in the root, return True. However, in example 2, it returns False because subRoot has unexpected child node. This Question set it is false like example 2. Solution(Recursion with DFS): Before looking at identical function, we should look the cases. In the first case, we return true when we don't have subRo..

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