Skip to content

Commit 827002b

Browse files
committed
feat: add 100 and fix code
1 parent 8f6f65d commit 827002b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+417
-300
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
|70|[Climbing Stairs][070]|Dynamic Programming|
2727
|83|[Remove Duplicates from Sorted List][083]|Linked List|
2828
|88|[Merge Sorted Array][088]|Array, Two Pointers|
29+
|100|[Same Tree][100]|Tree, Depth-first Search|
2930

3031

3132
## Medium
@@ -69,6 +70,7 @@
6970
[070]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/070/README.md
7071
[083]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/083/README.md
7172
[088]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/088/README.md
73+
[100]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/100/README.md
7274

7375
[008]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/008/README.md
7476
[019]: https://github.com/Blankj/awesome-java-leetcode/blob/master/note/019/README.md

note/001/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ return [0, 1].
2323
题意是让你从给定的数组中找到两个元素的和为指定值的两个索引,最容易的当然是循环两次,复杂度为`O(n^2)`,首次提交居然是2ms,打败了100%的提交,谜一样的结果,之后再次提交就再也没跑到过2ms了。
2424

2525
``` java
26-
public class Solution {
26+
class Solution {
2727
public int[] twoSum(int[] nums, int target) {
2828
int st = 0, end = nums.length;
2929
for (int i = 0; i < end; ++i) {

note/007/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The input is assumed to be a 32-bit signed integer. Your function should **retur
3232
题意是给你一个整型数,求它的逆序整型数,而且有个小坑点,当它的逆序整型数溢出的话,那么就返回0,用我们代码表示的话可以求得结果保存在long中,最后把结果和整型的两个范围比较即可。
3333

3434
``` java
35-
public class Solution {
35+
class Solution {
3636
public int reverse(int x) {
3737
long res = 0;
3838
for (; x != 0; x /= 10)

note/008/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ If no valid conversion could be performed, a zero value is returned. If the corr
2828
题意是把一个字符串转为整型,但要注意所给的要求,先去除最前面的空格,然后判断正负数,注意正数可能包含`+`,如果之后存在非数字或全为空则返回`0`,而如果合法的值超过int表示的最大范围,则根据正负号返回`INT_MAX``INT_MIN`
2929

3030
``` java
31-
public class Solution {
31+
class Solution {
3232
public int myAtoi(String str) {
3333
int i = 0, ans = 0, sign = 1, len = str.length();
3434
while (i < len && str.charAt(i) == ' ') ++i;

note/009/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ There is a more generic way of solving this problem.
2424
题意是判断一个有符号整型数是否是回文,也就是逆序过来的整数和原整数相同,首先负数肯定不是,接下来我们分析一下最普通的解法,就是直接算出他的回文数,然后和给定值比较即可。
2525

2626
``` java
27-
public class Solution {
27+
class Solution {
2828
public boolean isPalindrome(int x) {
2929
if (x < 0) return false;
3030
int copyX = x, reverse = 0;

note/013/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Input is guaranteed to be within the range from 1 to 3999.
2020
那么我们可以利用map来完成罗马数字的7个数字符号:I、V、X、L、C、D、M和整数的映射关系,然后根据上面的解释来模拟完成即可。
2121

2222
``` java
23-
public class Solution {
23+
class Solution {
2424
public int romanToInt(String s) {
2525
Map<Character, Integer> map = new HashMap<>();
2626
map.put('I', 1);

note/014/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Write a function to find the longest common prefix string amongst an array of st
1212
题意是让你从字符串数组中找出公共前缀,我的想法是找出最短的那个字符串的长度`minLen`,然后在`0...minLen`的范围比较所有字符串,如果比较到有不同的字符,那么直接返回当前索引长度的字符串即可,否则最后返回最短的字符串即可。
1313

1414
``` java
15-
public class Solution {
15+
class Solution {
1616
public String longestCommonPrefix(String[] strs) {
1717
int len = strs.length;
1818
if (len == 0) return "";

note/019/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Try to do this in one pass.
3434
* ListNode(int x) { val = x; }
3535
* }
3636
*/
37-
public class Solution {
37+
class Solution {
3838
public ListNode removeNthFromEnd(ListNode head, int n) {
3939
ListNode pre = head;
4040
ListNode afterPreN = head;

note/020/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The brackets must close in the correct order, `"()"` and `"()[]{}"` are all vali
1414
题意是判断括号匹配是否正确,很明显,我们可以用栈来解决这个问题,当出现左括号的时候入栈,当遇到右括号时,判断栈顶的左括号是否何其匹配,不匹配的话直接返回`false`即可,最终判断是否空栈即可,这里我们可以用数组模拟栈的操作使其操作更快,有个细节注意下`top = 1;`,从而省去了之后判空的操作和`top - 1`导致数组越界的错误。
1515

1616
``` java
17-
public class Solution {
17+
class Solution {
1818
public boolean isValid(String s) {
1919
int len = s.length();
2020
char[] stack = new char[len + 1];

note/021/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Your function should return length = `2`, with the first two elements of *nums*
2727
* ListNode(int x) { val = x; }
2828
* }
2929
*/
30-
public class Solution {
30+
class Solution {
3131
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
3232
ListNode head = new ListNode(0);
3333
ListNode temp = head;

0 commit comments

Comments
 (0)