随笔分类 -  Array

摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.思路: 从 points[] 中依次取出一个点,然后依次和后面一个点组成一条直线。 y = ax+b;然后... 阅读全文
posted @ 2014-02-20 10:27 Razer.Lu 阅读(238) 评论(0) 推荐(0)
摘要:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requi... 阅读全文
posted @ 2014-02-18 08:33 Razer.Lu 阅读(165) 评论(0) 推荐(0)
摘要:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文
posted @ 2014-02-18 08:16 Razer.Lu 阅读(321) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-02-17 16:57 Razer.Lu 阅读(222) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-02-17 15:22 Razer.Lu 阅读(187) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2014-02-17 15:09 Razer.Lu 阅读(160) 评论(0) 推荐(0)
摘要:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of ... 阅读全文
posted @ 2014-02-17 13:59 Razer.Lu 阅读(263) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文
posted @ 2014-02-17 03:07 Razer.Lu 阅读(210) 评论(0) 推荐(0)
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.For example:Given array A =[2,3,1,1,4]The minimum n 阅读全文
posted @ 2014-02-07 01:57 Razer.Lu 阅读(238) 评论(0) 推荐(0)
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], returnfalse. 1 阅读全文
posted @ 2014-02-07 01:20 Razer.Lu 阅读(275) 评论(0) 推荐(0)
摘要:Two pointerspublic class Solution { public ArrayList> threeSum(int[] num) { ArrayList> result = new ArrayList>(); Arrays.sort(num); ... 阅读全文
posted @ 2014-01-25 17:25 Razer.Lu 阅读(185) 评论(0) 推荐(0)
摘要:public class Solution { public int[] twoSum(int[] numbers, int target) { // IMPORTANT: Please reset any member data you declared, as ... 阅读全文
posted @ 2014-01-25 17:21 Razer.Lu 阅读(132) 评论(0) 推荐(0)
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Example 2:Given[1,2],[3,5],[6,7],[8 阅读全文
posted @ 2014-01-24 12:22 Razer.Lu 阅读(167) 评论(0) 推荐(0)
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n)time and uses constant space.ref:http://www.cnblogs.com/AnnieKim/archive/2013/04/21/3034631.html虽然不能再另外开辟非常数级的额外空间,但是可以在输入数组上就地进行swap操作。思路:交换数 阅读全文
posted @ 2014-01-24 02:52 Razer.Lu 阅读(221) 评论(0) 推荐(0)