摘要:
参考之前做的Search In Rotated Sorted Array,与之前略有不一样的是要多传一个min。public class Solution { public int findMin(int[] num) { if(num == null || num.length... 阅读全文
posted @ 2014-12-30 13:22
江南第一少
阅读(122)
评论(0)
推荐(0)
摘要:
一般的二分查找都是low = mid - 1或者high = mid + 1之类来避免重复,但此题必须要比较两个数值,故而要low=mid或者high = mid。public class Solution { public int findMin(int[] num) { if... 阅读全文
posted @ 2014-12-30 12:50
江南第一少
阅读(78)
评论(0)
推荐(0)
摘要:
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the... 阅读全文
posted @ 2014-12-30 11:56
江南第一少
阅读(126)
评论(0)
推荐(0)
摘要:
先按空格split, 然后把不是空格的加进一个list,然后reverse list,然后连起来。public class Solution { public String reverseWords(String s) { if(s == null || s.length() =... 阅读全文
posted @ 2014-12-30 11:06
江南第一少
阅读(104)
评论(0)
推荐(0)
摘要:
自己裸写,一遍过,牛!搜了一下,别人跟我写的差不多,还有讲解: 戳参考链接public class Solution { public int evalRPN(String[] tokens) { Stack s = new Stack(); for(int i =... 阅读全文
posted @ 2014-12-30 10:25
江南第一少
阅读(100)
评论(0)
推荐(0)
摘要:
数学题,以任意一点为中心,算其他所有点跟该点得斜率,斜率相同则在同一条直线上,用hashmap记下同一直线上的数字。要注意corner case,坐标完全相同的点,以及横坐标相同的点(相当于斜率为无穷)。遍历以每一个点为中心,更新最大值,即可得结果。public class Solution { ... 阅读全文
posted @ 2014-12-30 09:40
江南第一少
阅读(119)
评论(0)
推荐(0)
摘要:
这道题是一个数据结构设计题,在leetcode里面就这么一道,还是挺经典的一道题,可以好好看看。这道题要求设计实现LRU cache的数据结构,实现set和get功能。学习过操作系统的都应该知道,cache作为缓存可以帮助快速存取数据,但是确定是容量较小。这道题要求实现的cache类型是LRU,LR... 阅读全文
posted @ 2014-12-30 05:13
江南第一少
阅读(199)
评论(0)
推荐(0)

浙公网安备 33010602011771号