Skip to content

Commit de13f7e

Browse files
committed
20190318
1 parent 9e2990c commit de13f7e

15 files changed

+17
-16
lines changed

code/lc104.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public class TreeNode {
1919
TreeNode(int x) { val = x; }
2020
}
2121
public int maxDepth(TreeNode root) {
22-
if(root==null)
23-
return 0;
22+
if(root==null) return 0;
2423
return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
2524
}
2625

code/lc113.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* 难度:Medium
99
* 分类:Tree, Depth-first Search
1010
* 思路:回溯,注意因为节点上可能正值,可能负值,所以不能剪枝
11-
* Tips:
11+
* Tips:lc124
1212
*/
1313
public class lc113 {
1414
public class TreeNode {

code/lc124.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* 分类:Tree, Depth-first Search
77
* 思路:因为二叉树只有两个节点,一条路径可以想象成倒V字,从低层的某个节点一路向上,到达一个顶点,再一路向下,理解了这一点,整道题就好解了。
88
* Tips:用了一个全局变量存储最后结果,因为函数返回的是直线路径上的最优解,而不是V字路径最优解
9+
* lc133
910
*/
1011
public class lc124 {
1112
public class TreeNode {

code/lc127.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* 分类:Breadth-first Search
77
* 思路:bfs, 利用双向bfs可以加快搜索https://leetcode.com/problems/word-ladder/discuss/40711/Two-end-BFS-in-Java-31ms.
88
* Tips:拓扑排序,很经典的BFS,好好看看
9+
* lc207
910
*/
1011
import java.util.ArrayDeque;
1112
import java.util.List;

code/lc139.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* 分类:Dynamic Programming
77
* 思路:动态规划
88
* Tips:巧妙的方法,防止了复杂的操作,通过遍历之前计算出来的结果
9+
* lc140
910
*/
1011
import java.util.List;
1112

code/lc141.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 难度:Easy
66
* 分类:Linked List, Two Pointers
77
* 思路:快慢指针
8+
* lc142
89
*/
910
public class lc141 {
1011
public class ListNode {

code/lc162.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 题意:找出数组中任意一个山顶点,时间复杂度O(lg(n)),山顶点指该数左右两边都的数都小于他
55
* 难度:Medium
66
* 分类:Array, Binary Search
7-
* 思路:二分查找,想好左右两边递归判断。只有nums[mid]<nums[mid+1],说名右半边就存在峰值
7+
* 思路:二分查找,想好左右两边递归判断。只要nums[mid]<nums[mid+1],说明右半边就存在峰值
88
* Tips:
99
*/
1010
public class lc162 {

code/lc169.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* 题意:数组中有一个元素出现次数 >len/2 ,找出这个数
55
* 难度:Easy
66
* 分类:Array, Divide and Conquer, Bit Maniputation
7-
* 思路:很多种方法, Hashmap 是 O(n), O(n)的。 快排是O(log(n)), O(1)的。最巧妙的办法是 O(n), O(1) 的如下。
7+
* 思路:很多种方法, Hashmap 是 O(n), O(n)的。 快排是O(n), O(1)的。最巧妙的办法是 O(n), O(1) 的如下。
88
* Tips:之所以能够 O(n), O(1) 是因为题目已经给定了数组中一定能找到这个数,该方法充分利用了这一点
99
*/
1010
public class lc169 {
1111
public int majorityElement(int[] nums) {
1212
int res = nums[0];
1313
int count = 1;
14-
for (int i = 1; i < nums.length ; i++) {
14+
for (int i = 1; i < nums.length ; i++) { // 摩尔投票法,看这个数出现了几次
1515
if(nums[i]!=res) // 不是这个数就 --, ==0就用当前数替换res
1616
count--;
1717
else

code/lc189.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 题意:数组向后移几位,超出末尾的补到前边
55
* 难度:Easy
66
* 分类:Array
7-
* 思路:一种换状替换,别忘了可能是多个环。
7+
* 思路:一种环状替换,别忘了可能是多个环。
88
* reverse 的方法,先整体反转,再按照k划分成两个数组分别反转
99
* Tips:
1010
*/

code/lc198.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* 分类:Dynamic Programming
77
* 思路:经典的dp题,记一下
88
* Tips:时间复杂度为 O(n)
9+
* lc213
910
*/
1011
public class lc198 {
1112
public int rob(int[] nums) {

0 commit comments

Comments
 (0)