Skip to content

Commit ea4ea28

Browse files
committed
20190818
1 parent 4ca0257 commit ea4ea28

23 files changed

+175
-52
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
*/.DS_Store
3-
/kickstart/*
3+
kickstart/*
44
test.java
5+
interview/*

code/lc1026.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package code;
22
/*
3-
* 1025. Maximum Difference Between Node and Ancestor
3+
* 1026. Maximum Difference Between Node and Ancestor
44
* 题意:父节点减子节点的绝对值最大
55
* 难度:
66
* 分类:

code/lc105.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,17 @@ public static TreeNode recursion(int[] preorder, int[] inorder, int pre_index, i
3737
return tn; //记住函数的返回值的设置,返回Node,递归的构造子树
3838
}
3939

40+
public TreeNode buildTree2(int[] preorder, int[] inorder) {
41+
return helper(preorder, inorder, 0, 0, preorder.length-1);
42+
}
43+
public TreeNode helper(int[] preorder, int[] inorder, int cur, int left, int right){
44+
if(left>right) return null;
45+
TreeNode tn = new TreeNode(preorder[cur]);
46+
int i = left;
47+
for(; i<=right; i++) if(inorder[i]==preorder[cur]) break;
48+
tn.left = helper(preorder, inorder, cur+1, left, i-1);
49+
tn.right = helper(preorder, inorder, cur+i-left+1, i+1, right);
50+
return tn;
51+
}
52+
4053
}

code/lc113.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void helper(List<List<Integer>> res, List<Integer> cur, TreeNode root, in
3333
helper(res, cur, root.left, sum-root.val);
3434
helper(res, cur, root.right, sum-root.val);
3535
}
36-
cur.remove(cur.size()-1);
36+
cur.remove(cur.size()-1); //注意是去掉最后一个,传的是索引。传递对象的话,序列可能会变。
3737
return;
3838
}
3939
}

code/lc148.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public void quickSort(ListNode head, ListNode end) {
7575

7676
public ListNode partion(ListNode head, ListNode end) {
7777
ListNode p1 = head, p2 = head.next;
78-
78+
//p1指的是小于pivot的索引
7979
//走到末尾才停
80-
while (p2 != end) { //p1与p2间都是大于pivot的数
80+
while (p2 != end) { //head到p1间是小于pivot的数,p1与p2间都是大于pivot的数
8181
if (p2.val < head.val) { //lc922 类似的思想, 把小于的值放到该放的位置上
8282
p1 = p1.next;
8383

code/lc149.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Point {
2020
public int maxPoints(Point[] points) {
2121
if(points.length<=2) return points.length;
2222
int res = 0;
23-
for (int i = 0; i < points.length-1 ; i++) {
23+
for (int i = 0; i < points.length-1 ; i++) {//先固定一个点,再根据斜率进行记录就行了
2424
HashMap<Integer, HashMap<Integer, Integer>> hm = new HashMap<>();
2525
int overlap = 1;
2626
int max = 0;

code/lc153.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public int findMin(int[] nums) {
1616
int mid = (left+right)/2;
1717
if(nums[mid]<nums[right]){
1818
right = mid; //这不加1
19-
}else if(nums[mid]>nums[right]){
19+
}else{
2020
left = mid+1;
2121
}
2222
}

code/lc22.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package code;
22
/*
33
* 22. Generate Parentheses
4-
* 题意:正确括号组合的
4+
* 题意:正确括号组合
55
* 难度:Medium
66
* 分类:String, Backtracking
77
* 思路:回溯法的典型题目,按选优条件向前搜索,达到目标后就退回一步或返回

code/lc236.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {//
2323
return root;
2424
TreeNode left = lowestCommonAncestor(root.left, p, q);
2525
TreeNode right = lowestCommonAncestor(root.right, p, q);
26-
if( left!=null && right!=null ) //回溯返回。哪边不为空,返回哪边,否则返回自己。
27-
return root;
28-
else if(left!=null)
29-
return left;
26+
if( left!=null && right!=null ) return root; //回溯返回。哪边不为空,返回哪边,否则返回自己。
27+
else if(left!=null) return left;
3028
else return right;
3129
}
3230

code/lc239.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static int[] maxSlidingWindow(int[] nums, int k) {
2525
return new int[]{};
2626
int[] res = new int[nums.length-k+1];
2727
int cur = 0;
28-
Deque<Integer> dq = new ArrayDeque(); //队列里是递减的
28+
Deque<Integer> dq = new ArrayDeque(); //队列里是递减的,存的仍然是下标
2929
for (int i = 0; i < nums.length ; i++) {
3030
if( !dq.isEmpty() && dq.peekFirst()<=i-k) //窗口长度过长了,删掉头
3131
dq.removeFirst();

0 commit comments

Comments
 (0)