04 2015 档案
摘要:http://beginnersbook.com/2014/06/difference-between-hashmap-and-hashtable/http://www.importnew.com/7010.html
阅读全文
摘要:refhttp://inderpsingh.blogspot.com/2010/03/how-to-find-more-or-better-bugs-12-tips.htmlI copied directlyWell, we know that we do not find all the bugs...
阅读全文
摘要:我觉得这个算法比较陌生,对我不是简单题目public class Solution { public boolean isHappy(int n) { // 这个叫“模拟”的算法是什么http://meetqun.com/thread-8853-1-1.html H...
阅读全文
摘要:注意有很多地方关于long 和int的处理比如赋值n, d判断是否应该是负数的时候如果写成long n = (long) numerator>0? numerator: -numerator;long d = (long) denominator>0? denominator:-denominato...
阅读全文
摘要:Given a string S, find the length of the longest substring T that contains at most two distinct characters.Given S = “eceba”,T is “ece” which its leng...
阅读全文
摘要:基础题注意要bug free看清楚细节得public class Solution { public ListNode removeElements(ListNode head, int val) { if(head==null ) return null; Lis...
阅读全文
摘要:/** * Definition for a point. * class Point { * int x; * int y; * Point() { x = 0; y = 0; } * Point(int a, int b) { x = a; y = b; } * ...
阅读全文
摘要:摘抄自http://www.cnblogs.com/springfor/p/3870801.html“这道题运用位运算的异或。异或是相同为0,不同为1。所以对所有数进行异或,得出的那个数就是single number。初始时先让一个数与0异或,然后再对剩下读数挨个进行异或。这里运用到异或的性质:对于...
阅读全文
摘要:http://blog.csdn.net/linhuanmars/article/details/20187257http://blog.csdn.net/dongtingzhizi/article/details/8236181塞翁失马焉知非福---4/22/2014
阅读全文
摘要:refhttp://www.cnblogs.com/springfor/p/3874667.html高亮处"如果一个sorted word是在HashMap里面存在过的,说明这个词肯定是个变形词,除了把这个词加入到返回结果中,还需要把之前第一个存进HashMap里面的value存入result中。"...
阅读全文
摘要:经典题refhttp://blog.csdn.net/u011095253/article/details/9158473public class Solution { public ArrayList solveNQueens(int n) { ArrayList res = ...
阅读全文
摘要:最后一个block部分不一样,此外,helper最后的return true要想一想,小莹子的解释很好“对整个棋盘所有'.'都填完了,那么就可以返回true了。”public class Solution { public void solveSudoku(char[][] board) { ...
阅读全文
摘要:最后一个循环的问题比较值得学习,本质是n皇后public class Solution { public boolean isValidSudoku(char[][] board) { //http://blog.csdn.net/linhuanmars/article/deta...
阅读全文
摘要:压力太大了,这道题先不做了public class Solution { public String minWindow(String S, String T) { // 讲解http://articles.leetcode.com/2010/11/finding-minimum...
阅读全文
摘要:滑动窗口,但是很繁琐 public class Solution { public ArrayList findSubstring(String S, String[] L) { //http://www.cnblogs.com/springfor/p/3872516.html ...
阅读全文
摘要:经典问题,可以把周边都做了,详见ref http://blog.csdn.net/linhuanmars/article/details/19949159public class Solution { public int lengthOfLongestSubstring(String s) ...
阅读全文
摘要:题目看不到,所以网上搜刮http://www.danielbit.com/blog/puzzle/leetcode/leetcode-missing-ranges学习了一下public class Solution { public List findMissingRanges(int[] v...
阅读全文
摘要:public class Solution { public void rotate(int[] nums, int k) { if(nums==null||nums.length<2||k<1) return; int n = nums.length; ...
阅读全文
摘要:很有趣的一个算法,不过好像除此之外用处不大ref http://www.geeksforgeeks.org/majority-element/public int majorityElement(int[] num) { if(num.length<3) return num[0]; ...
阅读全文
摘要:public class Solution { public int findPeakElement(int[] num) { // binary search http://siddontang.gitbooks.io/leetcode-solution/content/arr...
阅读全文
摘要:之前一步一步存的方法略复杂啊,其实直接二分扔就可以咯这里直接给个II的解法,和I多个冗余挪位的判断public class Solution { public int findMin(int[] nums) { int min = nums[0]; int l=0,...
阅读全文
摘要:总结帖http://blog.csdn.net/linhuanmars/article/details/39366817code 参考帖http://www.cnblogs.com/springfor/p/3869981.htmlhttp://blog.csdn.net/linhuanmars/ar...
阅读全文
摘要:public class Solution { public int maxProfit(List prices) { // http://blog.csdn.net/linhuanmars/article/details/23236995 if(prices==n...
阅读全文
摘要:这几道题最好连着做, 模式就是loc 和global比,难点在于求出loc,咦,我做过这个梦吔I 只能交易一次,那么loc就和0比 loc = max(loc+diff, 0)为啥是loc+当天diff呢?比如 1,2,4, 1买进,2-1的差价在loc里存着,到了4 的时候4和1 的差价=4-2 ...
阅读全文
摘要:还是细节容易错画个图11 21 2 31 2 3 4很容易就出来了额public class Solution { public int minimumTotal(List> triangle) { int m = triangle.size() ; if(m==1...
阅读全文
摘要:想清楚了,安排好细节不难public class Solution { public ArrayList> generate(int numRows) { ArrayList> res = new ArrayList>(); if(numRows tmp = new...
阅读全文
摘要:跟另一道题一样,不多说了public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { // post就是pre的近似倒过来 if(inorder==null||...
阅读全文
摘要:refhttp://www.cnblogs.com/springfor/p/3884034.html以下解释摘抄自 爱做饭的小莹子“题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:Yo...
阅读全文
摘要:public class Solution { public void merge(int A[], int m, int B[], int n) { if(B==null||A==null) return; int ia=m-1,ib=n-1, len = A.l...
阅读全文
摘要:ref // http://www.cnblogs.com/springfor/p/3869492.html // http://blog.csdn.net/linhuanmars/article/details/24444491//https://leetcode.com/probl...
阅读全文
摘要:以下全部抄自“李二娃的博客”,地址http://www.cnblogs.com/lichen782/p/leetcode_Largest_Rectangle_in_Histogram.html说的超详细超有画面感,多谢作者的解释!==========羞羞的引用转载开始==============16...
阅读全文
摘要:跟1 差不多,就是多了个一旦相等,就挪边缘的条件, 参考http://blog.csdn.net/linhuanmars/article/details/20588511public class Solution { public boolean search(int[] A, int tar...
阅读全文
摘要:public class Solution { public int removeDuplicates(int[] A) { //http://needjobasap.blogspot.com/2014/01/remove-duplicates-from-sorted-array...
阅读全文
摘要:对于我来说 这种dfs之类的题目还是挺有难度的,尤其是各种条件和设计要想清楚, dfs经典题目,尤其是最后要退一步,高亮处public class Solution { public boolean exist(char[][] board, String word) { if(...
阅读全文
摘要:public class Solution { public ArrayList> subsetsWithDup(int[] num) { ArrayList> res = new ArrayList>(); res.add(new ArrayList()); ...
阅读全文
摘要:这道题虽然不用到helper,但是却是那一路的参考code 包括有helper的http://blog.csdn.net/linhuanmars/article/details/24286377public class Solution { public ArrayList> subsets(...
阅读全文
摘要:三个指针,就是比较容易糊涂,要想清楚public class Solution { public void sortColors(int[] A) { if(A==null || A.length0 && A[p2]==2){ p2--; } ...
阅读全文
摘要:这道题有两种解法,第一种最好想吧,2次两分法,第二种是维度变换详细解释refhttp://www.cnblogs.com/springfor/p/3857959.htmlpublic class Solution { public boolean searchMatrix(int[][] ma...
阅读全文
摘要:和感染列岛那道题有点共鸣http://www.cnblogs.com/jiajiaxingxing/p/4405731.html这道题就是细节比较多吧code ganker 的总结http://blog.csdn.net/linhuanmars/article/details/39248597pub...
阅读全文
摘要:public class Solution { public String multiply(String num1, String num2) { if(num1==null || num2==null || num1.length()*num2.length()==0) re...
阅读全文
摘要:都还好吧,就是细节要想清楚,简单public class Solution { public String addBinary(String a, String b) { if(a==null) return b; if(b==null) return a; ...
阅读全文
摘要:总结数据处理帖子http://blog.csdn.net/linhuanmars/article/details/39046243这道题看似简单,但是有个优化必须要考虑到,就是如果没有进位,则应该立即返回public class Solution { public int[] plusOne(...
阅读全文
摘要:主要是细节和把握一位数组的能力public class Solution { public int minPathSum(int[][] grid) { if(grid==null || grid.length==0 || grid[0].length==0) return 0;...
阅读全文
摘要:public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { if(obstacleGrid == null || obstacleGrid.length==0 || ob...
阅读全文
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ...
阅读全文
摘要:public class Solution { public ArrayList insert(ArrayList intervals, Interval newInterval) { ArrayList res = new ArrayList(); for(Int...
阅读全文
摘要:怎么写comparator是要会的public class Solution { public ArrayList merge(ArrayList intervals) { if(intervals==null || intervals.size() res = new Arra...
阅读全文
摘要:details killpublic class Solution { public ArrayList spiralOrder(int[][] matrix) { ArrayList res = new ArrayList(); if(matrix==null |...
阅读全文
摘要:主要是boundary的条件public class Solution { public void rotate(int[][] matrix) { if(matrix==null || matrix.length==0 || matrix[0].length==0) retur...
阅读全文
摘要:public class Solution { public int maxProduct(int[] A) { int res = A[0]; // max is local max, res is global max int tmax = res, tmin ...
阅读全文
摘要:refhttp://blog.csdn.net/linhuanmars/article/details/21314059DP经典题目,关于怎么动首尾部分,ref说的很明白public class Solution { public int maxSubArray(int[] A) { ...
阅读全文
摘要:Jump IGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your ...
阅读全文
摘要:主要是思想,坐标和值什么的容易搞混public class Solution { public int firstMissingPositive(int[] A) { for(int i=0; i0 && A[i]<=A.length && A[i] != A[A[i]-1] )...
阅读全文
摘要:比较典型的helper的题目,现在我还搞不太清楚dfs之类的,只能用helper来统称了,你明白那个调调就行public class Solution { public ArrayList> combinationSum(int[] candidates, int target) { ...
阅读全文
摘要:二分,多设立一个返回条件变可以继承二分法ublic class Solution { public int searchInsert(int[] A, int target) { int l = 0, r = A.length-1; while(lt...
阅读全文
摘要:public class Solution { public int[] searchRange(int[] A, int target) { int[] res = {-1, -1}; if(A==null || A.length<1) return res; ...
阅读全文
摘要:public class Solution { public int search(int[] A, int target) { if(A==null || A.length==0) return -1; int l = 0; i...
阅读全文
摘要:public class Solution { public int removeElement(int[] A, int elem) { if(A==null||A.length<1) return 0; // same http://www.cnblogs.co...
阅读全文
摘要:public class Solution { public int removeDuplicates(int[] A) { if(A==null || A.length==0) return 0; // 巧妙的做法http://www.cnblogs.com/sp...
阅读全文
摘要:public int maxArea(int[] height) { //http://blog.csdn.net/linhuanmars/article/details/21145429 贪心算法要看看 if(height==null || height.len...
阅读全文
摘要:感觉和Container With Most Water很像,这里有个问题,如果让球最大的坑,怎么做呢?还有candy那道题,好像都是这种双扫系列的refhttp://fisherlei.blogspot.com/2013/01/leetcode-trapping-rain-water.html双扫...
阅读全文
摘要:答案部分完全借鉴http://www.cnblogs.com/springfor/p/3861890.html以下是摘抄:“爱做饭的小莹子”题目:There are two sorted arrays A and B of size m and n respectively. Find the me...
阅读全文
摘要:很简单一道题,就是细节容易出错,必然是二分才有nlogn的速度public class Solution { public ListNode sortList(ListNode head) { // 跟merge sort 一模一样 http://www.cnblogs.com/...
阅读全文
摘要:原题解法超屌: ref http://blog.csdn.net/u012162613/article/details/41560337 public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(...
阅读全文
摘要:容易出错的点1 不是原位排序,惊讶!!2 要重新定位pre!!public class Solution { public ListNode insertionSortList(ListNode head) { // 想清楚怎么插入就很简单啦 if(head==nu...
阅读全文
摘要://t 牵引拔出元素cur.next,后面的位置,为后面连起来用// p2 牵引将要插入元素后面的位置,为后面连起来用public void reorderList(ListNode head) { if(head==null || head.next==null || head.ne...
阅读全文
摘要:写了无数次,今天终于自己想明白了,但是好像还是记住后明白的plotting tool:http://flowchart.com/public class Solution { public ListNode detectCycle(ListNode head) { if(head...
阅读全文
摘要:public class Solution { public boolean hasCycle(ListNode head) { if(head==null || head.next==null) return false; ListNode walk = head...
阅读全文
摘要:public class Solution { public RandomListNode copyRandomList(RandomListNode head) { //http://www.cnblogs.com/springfor/p/3864457.html ...
阅读全文
摘要:今天出来的新题,已经有大神出结果了,刚开始看还没看懂,就是dfs + 二维渲染 图http://www.cnblogs.com/easonliu/p/4402077.htmlpublic class Solution { public int numIslands(char[][] grid)...
阅读全文
摘要:public class Solution { public TreeNode sortedListToBST(ListNode head) { if(head==null) return null; int len = 0; ListNode t =...
阅读全文
摘要:public class Solution { public ListNode partition(ListNode head, int x) { if(head==null) return head; ListNode h = new ListNode(-1); ...
阅读全文
摘要:和I 比起来其实很不一样,反而很类似于linkedlist reverse,不断的看pre.next的东西,我自己想了好久,开始用三个指针,完全糊涂,还是退回到原来的code,才明了public class Solution { public ListNode deleteDuplicates...
阅读全文
摘要:看了别人讨论,双指针比较方便http://www.cnblogs.com/springfor/p/3862042.htmlpublic class Solution { public ListNode deleteDuplicates(ListNode head) { if(he...
阅读全文
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.小细节容易...
阅读全文
摘要:public class Solution { public ArrayList rightSideView(TreeNode root) { // 层遍历,利用queue http://bookshadow.com/weblog/2015/04/03/leetcode-bina...
阅读全文
摘要:折腾出来比较费劲,但是巩固了linked list reverse的概念如果有 pre -> 1 ->2 ->3 ->4 ->end返回的reverse是 原来的pre.next 也就是最后reversed 了以后的list: pre ->4 ->3 ->2 ->1 ->end的那个1,在这里,re...
阅读全文
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No...
阅读全文
摘要:关键是想好swap 的function怎么写我的做法是输入输出两支点pre& end,中间的两个node swappublic class Solution { public ListNode swapPairs(ListNode head) { if(head==null ||...
阅读全文
摘要:也很简单,关键是掌握mergeSort见ref http://www.cnblogs.com/springfor/p/3869217.html, 摘抄这里来复习一下Merge Sort(对于数组操作),参考Wikipedia:归并操作(merge),也叫归并算法,指的是将两个已经排序的序列合并成一个...
阅读全文
摘要:很简单public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode h = new ListNode(-1); ListNode l3 = h; ...
阅读全文
摘要:很简单的一道题,隐含条件要问清楚, n> len的时候就删除首个public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(head==null) return null;...
阅读全文
摘要:public class Solution { // http://www.cnblogs.com/springfor/p/3864493.html public ListNode addTwoNumbers(ListNode l1, ListNode l2) { List...
阅读全文
摘要:public class Solution { public ArrayList> fourSum(int[] num, int target) { // the same as 3sum ArrayList> res = new ArrayList>(); ...
阅读全文
摘要:public int threeSumClosest(int[] num, int target) { //int d = 0; if(num==null || num.length0) low++; if(M...
阅读全文
摘要:I 非排好序,最快O(n), 用hashmap解决public class Solution { public int[] twoSum(int[] numbers, int target) { int[] res = new int[2]; HashMap h...
阅读全文