Algorithm
文章平均质量分 66
xkfcl
这个作者很懒,什么都没留下…
展开
-
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 · 158 阅读 · 0 评论 -
[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 · 149 阅读 · 0 评论 -
[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 · 168 阅读 · 0 评论 -
[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 · 215 阅读 · 0 评论 -
[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 · 282 阅读 · 0 评论 -
[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 · 231 阅读 · 0 评论 -
[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 · 200 阅读 · 0 评论 -
[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 · 219 阅读 · 0 评论 -
[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 · 221 阅读 · 0 评论