Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc31857

Browse files
committed
0314
1 parent 47817b2 commit dc31857

File tree

12 files changed

+89
-10
lines changed

12 files changed

+89
-10
lines changed

‎code/lc100.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package code;
2+
/*
3+
* 100. Same Tree
4+
* 题意:判断两棵树是否一样
5+
* 难度:Easy
6+
* 分类:
7+
* 思路:
8+
* Tips:
9+
*/
10+
public class lc100 {
11+
public class TreeNode {
12+
int val;
13+
TreeNode left;
14+
TreeNode right;
15+
TreeNode(int x) {
16+
val = x;
17+
}
18+
}
19+
public boolean isSameTree(TreeNode p, TreeNode q) {
20+
if(p==null&&q==null) return true;
21+
if( (p==null&&q!=null)||(q==null&&p!=null) ) return false;
22+
if(p.val!=q.val) return false;
23+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
24+
}
25+
}

‎code/lc119.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package code;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/*
7+
* 119. Pascal's Triangle II
8+
* 题意:和118一样,就是输出不一样
9+
* 难度:Easy
10+
* 分类:Array
11+
* 思路:记一下 ArrayList.set 方法,不用重新 new ArrayList
12+
* Tips:
13+
*/
14+
public class lc119 {
15+
public List<Integer> getRow(int rowIndex) {
16+
ArrayList<Integer> res = new ArrayList<>();
17+
res.add(0,1);
18+
while(rowIndex-->0){
19+
res.add(0,1);
20+
for (int i = 1; i < res.size()-1 ; i++) {
21+
res.set(i, res.get(i)+res.get(i+1));
22+
}
23+
}
24+
return res;
25+
}
26+
}

‎code/lc14.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
import java.util.Arrays;
1010

1111
public class lc14 {
12-
public static void main(String[] args) {
13-
14-
}
15-
1612
public static String longestCommonPrefix(String[] strs) { //不是最优的方法,多做了比较
1713
if(strs.length==0)
1814
return "";

‎code/lc17.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 17. Letter Combinations of a Phone Number
66
* 题意:手机键盘字母输入
77
* 难度:Medium
8+
* 思路:思路记一下,每次放到vector中,遍历vector,加上所有的可能
89
* 分类:String, Backtracking
910
*/
1011
public class lc17 {

‎code/lc19.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 题意:删除链表中倒数第n个节点
55
* 难度:Medium
66
* 分类:Linked List, Two Pointers
7-
* 思路:快慢指针,快指针达到链表尾部时,满指针所在位置即为操作的节点
7+
* 思路:快慢指针,快指针达到链表尾部时,慢指针所在位置即为操作的节点
88
* 注意:看清题意,是倒数第n个,且复杂度为n
99
*/
1010
public class lc19 {

‎code/lc2.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
* 注意考虑两个链表长度不一致的问题
1010
*/
1111
public class lc2 {
12-
public static void main(String[] args) {
13-
14-
}
1512

1613
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
1714
int sum = 0;

‎code/lc26.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* 题意:移除数组中重复元素
55
* 难度:Easy
66
* 分类:Array, Two Pointers
7+
* lc27
78
*/
89
public class lc26 {
910
public static void main(String[] args) {

‎code/lc27.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* 分类:Array, Two Pointers
77
* 思路:两个指针,分别O(n),指向要交换的位置和和他交换的数
88
* 答案中直接遍历一遍数组,放到位置上就行了,i++
9-
* Tips:
9+
* Tips:lc26
1010
*/
1111
public class lc27 {
1212
public int removeElement(int[] nums, int val) {

‎code/lc28.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 难度:Easy
66
* 分类:Two Pointers, String
77
* Tips:注意判断子串为空的方法为needle.length()==0,不要用needle==""
8+
* 最优的解法应该是O(N)的,类似KMP的思路,不过面试不会让写KMP的
89
*/
910
public class lc28 {
1011
public static void main(String[] args) {

‎code/lc29.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 难度:Medium
66
* 分类:Math, Binary Search
77
* 思路:被除数减去除数,除数每次左移一位,也就是*2 来实现类似二分的思想
8-
* Tips:注意下用long类型,以及溢出的情况
8+
* Tips:注意下用long类型,以及溢出的情况,注意符号
99
*/
1010
public class lc29 {
1111
public static void main(String[] args) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /