Solution to House Robber by LeetCode

18 Jun

Question: https://leetcode.com/problems/house-robber/ Question Name: House Robber Simple DP problem. If you want, you could improve the space complexity to O(1) with bookkeeping (the second previous house, the previous house, and the current house).

Solution to Number of 1 Bits by LeetCode

1 Jun

Question: https://leetcode.com/problems/number-of-1-bits/ Question Name: Number of 1 Bits The key is how to find and remove the last 1-bit.

Solution to Reverse Bits by LeetCode

1 Jun

Question: https://leetcode.com/problems/reverse-bits/ Question Name: Reverse Bits Exactly same challege from Elements of Programming Interviews.

Solution to Rotate Array by LeetCode

28 May

Question: https://leetcode.com/problems/rotate-array/ Question Name: Rotate Array Classic Doug McIlroy’s Handwaving. It is very similar with some previous question.

Solution to Best Time to Buy and Sell Stock IV by LeetCode

25 May

Question: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/ Question Name: Best Time to Buy and Sell Stock IV Thanks to genius solution from @yishiluo.

Solution to Repeated DNA Sequences by LeetCode

29 Apr

Question: https://leetcode.com/problems/repeated-dna-sequences/ Question Name: Repeated DNA Sequences Simple brute force solution works.

Solution to Largest Number by LeetCode

29 Apr

Question: https://leetcode.com/problems/largest-number/ Question Name: Largest Number Conver the input numbers into strings. And then sort the strings according to special rule.

However, if you prefer a Python3 solution:

Solution to Binary Search Tree Iterator by LeetCode

24 Apr

Question: https://leetcode.com/problems/binary-search-tree-iterator/ Question Name: Binary Search Tree Iterator The challenge is a variant of the iterative in-order traversal of BST. However, yield in python is much much better in implementing iterator, right?