- 博客(9)
- 收藏
- 关注
原创 [LeetCode] Binary Tree Preorder Traversal
The recursive method is trivial. Just record the root and go left and go right. To do it iteratively, we need a stack to record the path. We go left until it's null. And pop the back out then go
2015-10-29 04:42:25
208
原创 [LeetCode] Paint House
This is a DP problem. Actually, most problems with minimum or maximum are DP. One thing need to notice in this problem is the symmetric. Paint from the first one is equal with paint from the last one.
2015-10-29 03:57:04
242
原创 [LeetCode] Product of Array Except Self
This problem is easy if we can use divide. The idea is get the product of all numbers and divide each of them to get the result we want. Linear time and constant space. Here we can't use this met
2015-10-29 00:31:22
179
原创 [LeetCode] Single Number III
This problem can also be solved using Hash map and this idea is quite simple on implementation. But how to do it in linear time and constant space? First of all, we know that if we do XOR t
2015-10-28 23:45:40
225
原创 [LeetCode] Best Time to Buy and Sell Stock II
The difference with previous one is: this time we can buy and sell the share multiple times. We can use greedy to solve this problem. Every time, if we have a local minimum, we buy it and sell it at t
2015-10-28 23:35:59
228
原创 [LeetCode] Best Meeting Point
Problem Description: A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the grou
2015-10-28 11:42:38
298
原创 [LeetCode] Two Sum II – Input array is sorted
This problem is similar with Two Sum. The solution is easy. Since they are sorted, we only need to get two pointers that point to head and tail respectively. Then move head one if the sum is smaller
2015-10-28 08:57:24
225
原创 [LeetCode] Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] . For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4]. For the given example,
2015-10-28 06:47:46
161
原创 LeetCode, Single Number
Given an array, each number appears twice except one, find that single one. First thinking is using Hash map, the key is each number and the value is their appearance times. This is a very intui
2015-10-28 03:29:25
163
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人