LeetCode ๐Ÿ”๏ธ/Binary

LeetCode ๐Ÿ”๏ธ/Binary

190. Reverse Bits

Today, I solved "Reverse Bits." Description: In this problem, we are gonna do reverse order of 32-bits number. Solution: "output" will store "0" or "1." If the bit number is 1, then the output store 1 in it. Otherwise, it stores 0. In output, we shift the bit left, and also we shift the bit right in n.

LeetCode ๐Ÿ”๏ธ/Binary

268. Missing Number

Today, I solved the Missing number. Description: In this question, we are asked to find missing number in nums. Solution: In this method, we are gonna subtract sum of nums from sum of every number of n. For example 2: The length of nums: 2 Range: [0, 2] sum([0, 1, 2]) - sum([0, 1] = 2 Space Complexity: O(1) Time Complexity: O(n)

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

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