LeetCode91 LeetCode. Reverse Bits Problem: Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000. Example 2: Input: 1111111111111111111111111111.. 2020. 6. 22. LeetCode 91. Decode Ways Problem: A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given a non-empty string containing only digits, determine the total number of ways to decode it. Example 1: Input: "12" Output: 2 Explanation: It could be decoded as "AB" (1 2) or "L" (12). Example 2: Input: "226" Output: 3 Explanation: It could be decoded as "B.. 2020. 6. 21. LeetCode. Pascal's Triangle Problem: Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. -Summary- Solved by dynamic programming approach (Below code is available from Leetcode solution) 1. The first and last element of each row is always 1. 2. Calculate inner elements by using and adding previous row elements. class Solution: def generate(self, num_rows): triangle = [] for row_num in ran.. 2020. 6. 21. LeetCode 226. Invert Binary Tree Problem: Invert a binary tree. Example: -Summary- Solved recursively 1. Until root node exist, we keep traverse left and right and change the left and right subtree by exchanging value. (By calling the function recursively) Here is another solution by solving this iteratively using stack. def invertTree(self, root): stack = [root] while stack: node = stack.pop() if node: node.left, node.right = .. 2020. 6. 20. Daily Coding Problem #5 Problem: cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4. Given this implementation of cons: def cons(a, b): def pair(f): return f(a, b) return pair Implement car and cdr. -Summary- def car(pair): def return_first(a, b): return a return pair(return_first) def cdr(pair).. 2020. 6. 19. Floor and Ceiling of a Binary Search Tree Problem: Given an integer k and a binary search tree, find the floor (less than or equal to) of k, and the ceiling (larger than or equal to) of k. If either does not exist, then print them as None. Here is the definition of a node for the tree. -Summary- 1. if root node is empty we return none value for both floor and ceil. 2. if root node is equal with k, return floor and cell with k value 3. i.. 2020. 6. 19. 이전 1 2 3 4 5 6 7 ··· 16 다음