自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(109)
  • 收藏
  • 关注

转载 two sum 攻

I 非排好序,最快O(n), 用hashmap解决public class Solution { public int[] twoSum(int[] numbers, int target) { int[] res = new int[2]; HashMap hm = new HashMap(); if(numbers==null |

2015-04-04 04:18:20 203

转载 天题之 Median of Two Sorted Arrays

public class Solution { public double findMedianSortedArrays(int A[], int B[]) { //直接没什么想法,看了答案也觉得万万想不到 ref http://www.cnblogs.com/springfor/p/3861890.html, http://blog.csdn.net/linhuanmar

2015-04-02 07:33:29 236

转载 Best Time to Buy and Sell Stock IV

public class Solution { public int maxProfit(int k, int[] prices) { // 这道题我有很大疑惑 ref http://blog.csdn.net/linhuanmars/article/details/23236995 // ref http://www.cnblogs.com/EdwardL

2015-04-02 05:29:05 220

转载 天题之Regular Expression Matching

反正我是想不出来注意几个case的情况public class Solution { public boolean isMatch(String s, String p) { // 反正我是想不出来 http://www.cnblogs.com/springfor/p/3893593.html if(p.length()==0) return s.l

2015-04-01 12:30:15 217

转载 House Robber

public class Solution { public int rob(int[] num) { // https://leetcode.com/discuss/30020/java-o-n-solution-space-o-1 不是很理解 int prevNo = 0; int prevYes = 0; for (int n : num) {

2015-04-01 09:14:03 203 1

转载 大数操作 Fraction to Recurring Decimal

1) 关于怎么变换大数字错误的点 ref https://leetcode.com/discuss/27159/my-java-solutionpublic class Solution { public String fractionToDecimal(int numerator, int denominator) { // 我觉得特别清晰受益的一个解法https

2015-04-01 06:43:29 206

转载 Candy 双扫

Candyref//http://www.cnblogs.com/springfor/p/3877120.html          //Trapping Rain Water public class Solution { public int candy(int[] ratings) { /

2015-03-31 05:14:32 213

转载 Trapping Rain Water 双扫

public class Solution { //http://fisherlei.blogspot.com/2013/01/leetcode-trapping-rain-water.html 双扫 public int trap(int[] A) { if (A.length<=2) return 0; int crtV = 0, re

2015-03-31 05:02:44 199

转载 Valid Sudoku

最后那个block search值得想想此外比hashset or map简单refhttp://blog.csdn.net/linhuanmars/article/details/20748171public class Solution { public boolean isValidSudoku(char[][] board) { //http:/

2015-03-31 04:05:12 170

转载 Sudoku Solver

1) n queen 问题,2) 说实话不理解 for(int r=i/3*3; r            for(int cl=j/3*3; clref http://www.cnblogs.com/springfor/p/3884252.htmlpublic class Solution { public void solveSudoku(char[][]

2015-03-31 03:12:25 198

转载 Binary Tree Maximum Path Sum

看似简单,但是为什么用数组做递归维护最高值,每个递归返回的是什么值? 当前node的最大值,包括1,node.val 2 node.left .max+ node.val 3 node.right.max + node.val值得学习refhttp://blog.csdn.net/fightforyourdream/article/details/16894069http://

2015-03-27 11:04:52 322

转载 难题部分Copy List with Random Pointer

别的都不说,这部分题对我来说,首先就是看不懂题意A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list./*

2015-03-27 05:48:56 227

转载 天题之 交织的字符串 二维dp规划,Interleaving String

首先别的不说,看懂题目都比较费劲其实还好public class Solution { public boolean isInterleave(String s1, String s2, String s3) { // ref http://www.cnblogs.com/springfor/p/3896159.html if(s1.le

2015-03-26 07:15:06 242

转载 天题之 三维数组dp Scramble String

public class Solution { public boolean isScramble(String s1, String s2) { // 讲解 http://blog.csdn.net/fightforyourdream/article/details/17707187 // 代码 http://www.blogjava.net/sandy/

2015-03-26 07:12:02 438

转载 Surrounded Regions

很有意思画面感的一道题,但是bfs不太会,注意linkedlist做queue的用法,不是pop 而是poll, 为啥想想得 public void solve(char[][] board) { // 挺有意思一道题,讲解 和code http://www.cnblogs.com/huntfor/p/3898068.html // XX

2015-03-26 03:33:50 323

转载 天题之reverse list

最后那个reverse函数写的比较费劲,主要是pre.next 和last.next必须指向正确位置ref 解释 http://www.cnblogs.com/lichen782/p/leetcode_Reverse_Nodes_in_kGroup.htmlref 代码 http://www.cnblogs.com/springfor/p/3864530.htmlpublic clas

2015-03-25 16:28:03 211

转载 天题之滑动窗口 Minimum Window Substring

不要用hashmappublic class Solution { public String minWindow(String S, String T) { // 讲解http://articles.leetcode.com/2010/11/finding-minimum-window-in-s-which.html //代码 http://www.c

2015-03-25 08:01:24 374

转载 天题之滑动窗口Substring with Concatenation of All Words

我觉得我没有理解第一层loop的精髓代码部分完全参考 ref public class Solution { public ArrayList findSubstring(String S, String[] L) { //http://www.cnblogs.com/springfor/p/3872516.html ArrayList res =

2015-03-25 04:40:15 228

转载 Maximal Rectangle

几个神奇的题目都是用这种 O(n)的算法出来的, 核心思想就是,“比我好的都算了”Largest Rectangle in Histogram Longest Valid Parentheses Maximal Rectanglerefhttp://blog.csdn.net/linhuanmars/article

2015-03-24 07:28:47 258

转载 Largest Rectangle in Histogram

ref http://www.cnblogs.com/lichen782/p/leetcode_Largest_Rectangle_in_Histogram.html弹栈天题public class Solution { public int largestRectangleArea(int[] height) { int i = 0; int re

2015-03-24 05:56:40 178

转载 Longest Valid Parentheses

public class Solution { public int longestValidParentheses(String s) { // http://blog.csdn.net/linhuanmars/article/details/20439613 if(s ==null || s.length()<2) return 0;

2015-03-24 04:21:46 229

转载 BM 算法和dp算法,不理解的题目

要多看看dp  //一下答案完全不懂 public int numDistinct(String S, String T) { int[][] dp = new int[S.length() + 1][T.length() + 1]; dp[0][0] = 1;//initial for(int j = 1; j

2015-03-22 08:21:18 374

转载 Edit Distance

public class Solution { public int minDistance(String word1, String word2) { // 题意讲解的很好http://www.cnblogs.com/springfor/p/3896167.html // 关于初始数组的设计!长度,第一行第一列什么的 in

2015-03-21 07:48:32 193

转载 Insert Interval

最后一个元素的处理是关键,要记得移动完成后加上去 public ArrayList insert(ArrayList intervals, Interval newInterval) { // 跟之前那道题一样嘛 不要那么麻烦http://www.cnblogs.com/springfor/p/3872333.html ArrayList res =

2015-03-21 06:47:29 207

转载 Merge Intervals

ref http://www.cnblogs.com/springfor/p/3872332.html1) 要先排序,按照start, 怎么写comparator是关键 class IntervalComparator implements Comparator {2) 然后按照end 在主程序里merge,public class Solution { // ref

2015-03-21 05:43:18 233

转载 Recover Binary Search Tree

重点1 inorder2 怎么用O(1)的space, 必然是用tmp的指针做swapref http://www.cnblogs.com/springfor/p/3891390.htmlpublic class Solution { TreeNode first, pre, second; public void recoverTree(TreeNode root

2015-03-21 05:26:26 186

转载 First Missing Positive

题目分析要求:转载自 https://leetcodenotes.wordpress.com/2013/07/17/first-missing-positive/要求这么高,还不让用空间换时间,说明不是dp,所以基本只让过一两遍数组,一边过一遍直接in place的改动数组(不让生成新数组啊)既然是大部分不missing,所以可以用index来直接和元素产生关系。试图让

2015-03-20 12:50:05 320

转载 Multiply Strings

ref 的code写的很漂亮 http://blog.csdn.net/fightforyourdream/article/details/17370495public class Solution { public String multiply(String num1, String num2) { if(num1==null||num2==null) return

2015-03-20 12:34:18 185

原创 Spiral Matrix

// 先看II,然后I就秒改public class Solution { public ArrayList spiralOrder(int[][] matrix) { ArrayList res = new ArrayList(); if(matrix==null || matrix.length==0 || matrix[0].length==0) re

2015-03-20 04:38:47 172

转载 Spiral Matrix II

public class Solution { public int[][] generateMatrix(int n) { // 模仿代码https://leetcodenotes.wordpress.com/2013/11/23/leetcode-spiral-matrix-%E6%8A%8A%E4%B8%80%E4%B8%AA2d-matrix%E7%94%A8%E8%9E%BA%E

2015-03-20 04:27:13 186

原创 Permutations II

public class Solution { public ArrayList> permuteUnique(int[] num) { // use hashset to keep uniqueness, 其他和I一样 ArrayList> res = new ArrayList>(); if(num==null || num.length

2015-03-19 11:18:48 151

原创 Permutations

public ArrayList> permute(int[] num) { ArrayList> res = new ArrayList>(); if(num==null || num.length==0) return res;ArrayList t = new ArrayList(); t.add(num[0]); res.a

2015-03-19 09:13:21 197

转载 Permutation Sequence

public String getPermutation(int n, int k) { // 比较难理解: http://blog.csdn.net/linhuanmars/article/details/22028697, http://www.cnblogs.com/springfor/p/3896201.html if(n==0 ) return null;

2015-03-19 05:17:27 196

原创 Rotate List

做个circle ,看讨论来的关键是怎么找到从哪里切,最后个循环的条件 len - k%lenpublic class Solution { public ListNode rotateRight(ListNode head, int k) { if(head==null || head.next == null ||k==0) return head;

2015-03-18 11:20:27 185

转载 Reorder List

1) 怎么写reverse linkedlist 逻辑图 http://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/2) 注意first half和second half 都要有null 结尾ref http://www.cnblogs.com/springfor/p/386933

2015-03-18 09:02:07 275

转载 Simplify Path

熟悉数据结构,linkedlist stack, string.split 等等public class Solution { public String simplifyPath(String path) { // ref http://www.cnblogs.com/springfor/p/3869666.html if(path == null |

2015-03-18 00:43:23 188

转载 Set Matrix Zeroes

1) 预设标准row col,在这里是first row col2)提前存好original 标准row 和col的状况ref http://www.cnblogs.com/springfor/p/3888003.html public void setZeroes(int[][] matrix) { int row = matrix.length;

2015-03-17 13:17:04 218

转载 Word Search

1) dfs2) 维护visited 数组,dp类似3) 关于最后吧visited这一位清回false的解释ref http://www.cnblogs.com/springfor/p/3883942.htmlpublic class Solution { public boolean exist(char[][] board, String word) {

2015-03-17 12:42:10 372

转载 Divide Two Integers

1) 加速-减速过程,先减去最大的b^power, 然后减小点的b^pow2) 移位判断符号3) 各种数据类型是long还是intref http://blog.csdn.net/perfect8886/article/details/19092179ref http://www.cnblogs.com/springfor/p/3871008.htmlpublic cl

2015-03-17 08:32:02 198

转载 Sqrt(x)

1) 二分法的应用2) 关于不能开方的数,要返回什么ref http://www.cnblogs.com/springfor/p/3857772.htmlpublic class Solution { public int sqrt(int x) { // 巧妙使用二分法 // ref http://www.cnblogs.com

2015-03-17 07:23:34 240

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除