Python130 LeetCode.Single Number II Problem: Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,3,2] Output: 3 Example 2: Input: [0,1,0,1,0,1,99] Output: 99 -Summary- Solved by using dictionary. 1. for each numbe.. 2020. 6. 23. 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. 이전 1 2 3 4 5 6 7 ··· 22 다음