Movatterモバイル変換


[0]ホーム

URL:


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

Commitcee8c5e

Browse files
authored
Merge pull request#1 from Blankj/master
update
2 parentsb20263c +f05e6f9 commitcee8c5e

File tree

86 files changed

+3056
-440
lines changed

Some content is hidden

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

86 files changed

+3056
-440
lines changed

‎.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github:# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon:# Replace with a single Patreon username
5+
open_collective:# Replace with a single Open Collective username
6+
ko_fi:# Replace with a single Ko-fi username
7+
tidelift:# Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge:# Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay:# Replace with a single Liberapay username
10+
issuehunt:# Replace with a single IssueHunt username
11+
otechie:# Replace with a single Otechie username
12+
custom:https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/donate.png

‎README.md

Lines changed: 85 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#awesome-java-leetcode
22

3-
我如今是一名AndroidDeveloper,大学的我曾是一名ACMer,我一直认为数据结构和算法是作为一名程序员必须掌握和善于利用的,为了不让数据结构和算法淡出我的记忆,所以我打算重拾LeetCode之Algorithm,语言选择的是Java,题库会一点点完善起来,按简单,中等,困难分类,相应难度下按题号排序,源代码在[src][src]目录中,相关解题都在[note][note]目录中,想要学习数据结构和算法或打算刷LeetCode的小伙伴们欢迎star哦
3+
我如今是一名 AndroidDeveloper,大学的我曾是一名 ACMer,我一直认为数据结构和算法是作为一名程序员必须掌握和善于利用的,为了不让数据结构和算法淡出我的记忆,所以我打算重拾 LeetCode 之 Algorithm,语言选择的是 Java,题库会一点点完善起来,按简单,中等,困难分类,相应难度下按题号排序,源代码在[src][src]目录中,相关解题都在[note][note]目录中,想要学习数据结构和算法或打算刷 LeetCode 的小伙伴们欢迎 star 哦
44

5-
如今有机会面试Facebook,附上LeetCode上Facebook的面试题目序号,希望可以帮助到以后想入Facebook的小伙伴:-)
5+
如今有机会面试 Facebook,附上 LeetCode 上 Facebook 的面试题目序号,希望可以帮助到以后想入 Facebook 的小伙伴:-)
66

77
```
88
1,10,13,15,17,20,23,25,26,28,33,38,43,44,49,50,56,57,67,68,69,71,75,76
@@ -12,85 +12,96 @@
1212
341,377,380,398,404,410,461,477,494,523,525,534,535,543,554
1313
```
1414

15-
如果想知道更多公司LeetCode面试题,可以参看[Companies.md][companies]
15+
如果想知道更多公司 LeetCode 面试题,可以参看[Companies.md][companies]
1616

1717
附上镇楼诗:
1818

19-
>明有科举八股,今有LeetCode
20-
>八股定格式而取文采心意,LeetCode定题目且重答案背诵
19+
>明有科举八股,今有 LeetCode
20+
>八股定格式而取文采心意,LeetCode 定题目且重答案背诵
2121
>美其名曰:"practice makes perfect."
2222
>为何今不如古?
2323
>非也非也,
24-
>科举为国取士,LeetCode为Google筛码工,各取所需也。
24+
>科举为国取士,LeetCode 为 Google 筛码工,各取所需也。
2525
2626

2727
##Easy
2828

29-
|#|Title|Tag|
30-
|:-------------|:-------------|:-------------|
31-
|1|[Two Sum][001]|Array, Hash Table|
32-
|7|[Reverse Integer][007]|Math|
33-
|9|[Palindrome Number][009]|Math|
34-
|13|[Roman to Integer][013]|Math, String|
35-
|14|[Longest Common Prefix][014]|String|
36-
|20|[Valid Parentheses][020]|Stack, String|
37-
|21|[Merge Two Sorted Lists][021]|Linked List|
38-
|26|[Remove Duplicates from Sorted Array][026]|Array, Two Pointers|
39-
|27|[Remove Element][027]|Array, Two Pointers|
40-
|28|[Implement strStr()][028]|Two Pointers, String|
41-
|35|[Search Insert Position][035]|String|
42-
|38|[Count and Say][038]|String|
43-
|53|[Maximum Subarray][053]|Array,Dynamic Programming,Divide and Conquer|
44-
|58|[Length of Last Word][058]|String|
45-
|66|[Plus One][066]|Array, Math|
46-
|67|[Add Binary][067]|Math, String|
47-
|69|[Sqrt(x)][069]|Binary Search, Math|
48-
|70|[Climbing Stairs][070]|Dynamic Programming|
49-
|83|[Remove Duplicates from Sorted List][083]|Linked List|
50-
|88|[Merge Sorted Array][088]|Array, Two Pointers|
51-
|100|[Same Tree][100]|Tree, Depth-first Search|
52-
|101|[Symmetric Tree][101]|Tree, Depth-first Search, Breadth-first Search|
53-
|104|[Maximum Depth of Binary Tree][104]|Tree, Depth-first Search|
54-
|107|[Binary Tree Level Order Traversal II][107]|Tree, Breadth-first Search|
55-
|108|[Convert Sorted Array to Binary Search Tree][108]|Tree, Depth-first Search|
56-
|110|[Balanced Binary Tree][110]|Tree, Depth-first Search|
57-
|111|[Minimum Depth of Binary Tree][111]|Tree, Depth-first Search, Breadth-first Search|
58-
|112|[Path Sum][112]|Tree, Depth-first Search|
59-
|118|[Pascal's Triangle][118]|Array|
60-
|119|[Pascal's Triangle II][119]|Array|
61-
|121|[Best Time to Buy and Sell Stock][121]|Array, Dynamic Programmin|
62-
|122|[Best Time to Buy and Sell Stock II][122]|Array, Greedy|
63-
|543|[Diameter of Binary Tree][543]|Tree|
29+
| #|Title|Tag|
30+
|:---| :---------------------------------------| :---------------------------------------|
31+
| 1|[Two Sum][001]|Array, Hash Table|
32+
| 7|[Reverse Integer][007]|Math|
33+
| 9|[Palindrome Number][009]|Math|
34+
| 13|[Roman to Integer][013]|Math, String|
35+
| 14|[Longest Common Prefix][014]|String|
36+
| 20|[Valid Parentheses][020]|Stack, String|
37+
| 21|[Merge Two Sorted Lists][021]|Linked List|
38+
| 26|[Remove Duplicates from Sorted Array][026]|Array, Two Pointers|
39+
| 27|[Remove Element][027]|Array, Two Pointers|
40+
| 28|[Implement strStr()][028]|Two Pointers, String|
41+
| 35|[Search Insert Position][035]|String|
42+
| 38|[Count and Say][038]|String|
43+
| 53|[Maximum Subarray][053]|Array, Divide and Conquer, Dynamic Programming|
44+
| 58|[Length of Last Word][058]|String|
45+
| 66|[Plus One][066]|Array, Math|
46+
| 67|[Add Binary][067]|Math, String|
47+
| 69|[Sqrt(x)][069]|Binary Search, Math|
48+
| 70|[Climbing Stairs][070]|Dynamic Programming|
49+
| 83|[Remove Duplicates from Sorted List][083]|Linked List|
50+
| 88|[Merge Sorted Array][088]|Array, Two Pointers|
51+
|100|[Same Tree][100]|Tree, Depth-first Search|
52+
|101|[Symmetric Tree][101]|Tree, Depth-first Search, Breadth-first Search|
53+
|104|[Maximum Depth of Binary Tree][104]|Tree, Depth-first Search|
54+
|107|[Binary Tree Level Order Traversal II][107]|Tree, Breadth-first Search|
55+
|108|[Convert Sorted Array to Binary Search Tree][108]|Tree, Depth-first Search|
56+
|110|[Balanced Binary Tree][110]|Tree, Depth-first Search|
57+
|111|[Minimum Depth of Binary Tree][111]|Tree, Depth-first Search, Breadth-first Search|
58+
|112|[Path Sum][112]|Tree, Depth-first Search|
59+
|118|[Pascal's Triangle][118]|Array|
60+
|119|[Pascal's Triangle II][119]|Array|
61+
|121|[Best Time to Buy and Sell Stock][121]|Array, Dynamic Programmin|
62+
|122|[Best Time to Buy and Sell Stock II][122]|Array, Greedy|
63+
|543|[Diameter of Binary Tree][543]|Tree|
6464

6565

6666
##Medium
6767

68-
|#|Title|Tag|
69-
|:-------------|:-------------|:-------------|
70-
|2|[Add Two Numbers][002]|Linked List, Math|
71-
|3|[Longest Substring Without Repeating Characters][003]|Hash Table, Two Pointers, String|
72-
|8|[String to Integer (atoi)][008]|Math, String|
73-
|15|[3Sum][015]|Array, Two Pointers|
74-
|17|[Letter Combinations of a Phone Number][017]|String, Backtracking|
75-
|19|[Remove Nth Node From End of List][019]|Linked List, Two Pointers|
76-
|33|[Search in Rotated Sorted Array][033]|Arrays, Binary Search|
77-
|43|[Multiply Strings][043]|Math, String|
78-
|49|[Group Anagrams][049]|Hash Table, String|
79-
|50|[Pow(x, n)][050]|Math, Binary Search|
80-
|56|[Merge Intervals][056]|Array, Sort|
81-
|554|[Brick Wall][554]|Hash Table|
68+
| #| Title| Tag|
69+
| :---| :---------------------------------------| :-------------------------------|
70+
| 2|[Add Two Numbers][002]| Linked List, Math|
71+
| 3|[Longest Substring Without Repeating Characters][003]| Hash Table, Two Pointers, String|
72+
| 5|[Longest Palindromic Substring][005]| String, Dynamic Programming|
73+
| 6|[ZigZag Conversion][006]| String|
74+
| 8|[String to Integer (atoi)][008]| Math, String|
75+
| 11|[Container With Most Water][011]| Array, Two Pointers|
76+
| 12|[Integer to Roman][012]| Math, String|
77+
| 15|[3Sum][015]| Array, Two Pointers|
78+
| 15|[3Sum Closest][016]| Array, Two Pointers|
79+
| 17|[Letter Combinations of a Phone Number][017]| String, Backtracking|
80+
| 18|[4Sum][018]| Array, Hash Table, Two Pointers|
81+
| 19|[Remove Nth Node From End of List][019]| Linked List, Two Pointers|
82+
| 22|[Generate Parentheses][022]| String, Backtracking|
83+
| 24|[Swap Nodes in Pairs][024]| Linked List|
84+
| 29|[Divide Two Integers][029]| Math, Binary Search|
85+
| 33|[Search in Rotated Sorted Array][033]| Arrays, Binary Search|
86+
| 43|[Multiply Strings][043]| Math, String|
87+
| 49|[Group Anagrams][049]| Hash Table, String|
88+
| 50|[Pow(x, n)][050]| Math, Binary Search|
89+
| 56|[Merge Intervals][056]| Array, Sort|
90+
| 554|[Brick Wall][554]| Hash Table|
8291

8392

8493
##Hard
8594

86-
|#|Title|Tag|
87-
|:-------------|:-------------|:-------------|
88-
|4|[Median of Two Sorted Arrays][004]|Array, Binary Search, Divide and Conquer|
89-
|10|[Regular Expression Matching][010]|String, Dynamic Programming, Backtracking|
90-
|23|[Merge k Sorted Lists][023]|Linked List, Divide and Conquer, Heap|
91-
|25|[Reverse Nodes in k-Group][025]|Linked List|
92-
|44|[Reverse Nodes in k-Group][044]|String, Dynamic Programming, Backtracking, Greedy|
93-
|57|[Insert Interval][057]|Array, Sort|
95+
| #| Title| Tag|
96+
| :---| :---------------------------------------| :---------------------------------------|
97+
| 4|[Median of Two Sorted Arrays][004]| Array, Binary Search, Divide and Conquer|
98+
| 10|[Regular Expression Matching][010]| String, Dynamic Programming, Backtracking|
99+
| 23|[Merge k Sorted Lists][023]| Linked List, Divide and Conquer, Heap|
100+
| 25|[Reverse Nodes in k-Group][025]| Linked List|
101+
| 30|[Substring with Concatenation of All Words][030]| Hash Table, Two Pointers, String|
102+
| 44|[Wildcard Matching][044]| String, Dynamic Programming, Backtracking, Greedy|
103+
| 57|[Insert Interval][057]| Array, Sort|
104+
| 68|[Text Justification][068]| String|
94105

95106

96107

@@ -135,10 +146,19 @@
135146

136147
[002]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/002/README.md
137148
[003]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/003/README.md
149+
[005]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/005/README.md
150+
[006]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/006/README.md
138151
[008]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/008/README.md
152+
[011]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/011/README.md
153+
[012]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/012/README.md
139154
[015]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/015/README.md
155+
[016]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/016/README.md
140156
[017]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/017/README.md
157+
[018]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/018/README.md
141158
[019]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/019/README.md
159+
[022]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/022/README.md
160+
[024]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/024/README.md
161+
[029]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/029/README.md
142162
[033]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/033/README.md
143163
[043]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/043/README.md
144164
[049]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/049/README.md
@@ -150,5 +170,7 @@
150170
[010]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/010/README.md
151171
[023]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/023/README.md
152172
[025]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/025/README.md
173+
[030]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/030/README.md
153174
[044]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/044/README.md
154175
[057]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/057/README.md
176+
[068]:https://github.com/Blankj/awesome-java-leetcode/blob/master/note/068/README.md

‎note/001/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ return [0, 1].
1818
**Tags:** Array, Hash Table
1919

2020

21-
##思路0
21+
##思路 0
2222

23-
题意是让你从给定的数组中找到两个元素的和为指定值的两个索引,最容易的当然是循环两次,复杂度为`O(n^2)`首次提交居然是2ms,打败了100%的提交,谜一样的结果,之后再次提交就再也没跑到过2ms了
23+
题意是让你从给定的数组中找到两个元素的和为指定值的两个索引,最容易的当然是循环两次,复杂度为`O(n^2)`首次提交居然是 2ms,打败了 100%的提交,谜一样的结果,之后再次提交就再也没跑到过 2ms 了
2424

2525
```java
2626
classSolution {
@@ -37,18 +37,19 @@ class Solution {
3737
}
3838
```
3939

40-
##思路1
40+
##思路 1
4141

42-
利用HashMap作为存储,键为目标值减去当前元素值,索引为值,比如`i = 0`时,此时首先要判断`nums[0] = 2`是否在map中,如果不存在,那么插入键值对`key = 9 - 2 = 7, value = 0`,之后当`i = 1`时,此时判断`nums[1] = 7`已存在于map中,那么取出该`value = 0`作为第一个返回值,当前`i`作为第二个返回值,具体代码如下所示。
42+
利用 HashMap 作为存储,键为目标值减去当前元素值,索引为值,比如`i = 0`时,此时首先要判断`nums[0] = 2` 是否在 map 中,如果不存在,那么插入键值对`key = 9 - 2 = 7, value = 0`,之后当`i = 1`时,此时判断`nums[1] = 7` 已存在于 map 中,那么取出该`value = 0`作为第一个返回值,当前`i`作为第二个返回值,具体代码如下所示。
4343

4444
```java
4545
classSolution {
4646
publicint[]twoSum(int[]nums,inttarget) {
4747
int len= nums.length;
4848
HashMap<Integer,Integer> map=newHashMap<>();
4949
for (int i=0; i< len;++i) {
50-
if (map.containsKey(nums[i])) {
51-
returnnewint[]{map.get(nums[i]), i};
50+
finalInteger value= map.get(nums[i]);
51+
if (value!=null) {
52+
returnnewint[] { value, i };
5253
}
5354
map.put(target- nums[i], i);
5455
}
@@ -60,7 +61,7 @@ class Solution {
6061

6162
##结语
6263

63-
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我GitHub上的LeetCode题解[awesome-java-leetcode][ajl]
64+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解[awesome-java-leetcode][ajl]
6465

6566

6667

‎note/002/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22

33
##Description
44

5-
You are given two**non-empty** linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
5+
You are given two**non-empty** linked lists representing two non-negative integers. The digits are stored in**reverse order** and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
66

77
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
88

9-
**Input:** (2 -> 4 -> 3) + (5 -> 6 -> 4)
10-
**Output:** 7 -> 0 -> 8
9+
**Example**
10+
11+
```
12+
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
13+
Output: 7 -> 0 -> 8
14+
Explanation: 342 + 465 = 807.
15+
```
1116

1217
**Tags:** Linked List, Math
1318

1419

1520
##思路
1621

17-
题意我也是看了好久才看懂,就是以链表表示一个数,低位在前,高位在后,所以题中的例子就是`342 + 465 = 807`,所以我们模拟计算即可。
22+
题意我也是看了好久才看懂,就是以链表表示一个数,低位在前,高位在后,所以题中的例子就是`342 + 465 = 807`,所以我们模拟计算即可。
1823

1924
```java
2025
/**
@@ -52,7 +57,7 @@ class Solution {
5257

5358
##结语
5459

55-
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我GitHub上的LeetCode题解[awesome-java-leetcode][ajl]
60+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解[awesome-java-leetcode][ajl]
5661

5762

5863

‎note/003/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Given `"abcabcbb"`, the answer is `"abc"`, which the length is 3.
1010

1111
Given`"bbbbb"`, the answer is`"b"`, with the length of 1.
1212

13-
Given`"pwwkew"`, the answer is`"wke"`, with the length of 3. Note that the answer must be a**substring**,`"pwke"` is a*subsequence*and not a substring.
13+
Given`"pwwkew"`, the answer is`"wke"`, with the length of 3. Note that the answer must be a**substring**,`"pwke"` is a*subsequence*and not a substring.
1414

1515
**Tags:** Hash Table, Two Pointers, String
1616

1717

1818
##思路
1919

20-
题意是计算不带重复字符的最长子字符串的长度,开辟一个hash数组来存储该字符上次出现的位置,比如`hash[a] = 3`就是代表`a`字符前一次出现的索引在3,遍历该字符串,获取到上次出现的最大索引(只能向前,不能退后),与当前的索引做差获取的就是本次所需长度,从中迭代出最大值就是最终答案。
20+
题意是计算不带重复字符的最长子字符串的长度,开辟一个 hash 数组来存储该字符上次出现的位置,比如`hash[a] = 3`就是代表`a` 字符前一次出现的索引在 3,遍历该字符串,获取到上次出现的最大索引(只能向前,不能退后),与当前的索引做差获取的就是本次所需长度,从中迭代出最大值就是最终答案。
2121

2222
```java
2323
classSolution {
@@ -43,7 +43,7 @@ class Solution {
4343

4444
##结语
4545

46-
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我GitHub上的LeetCode题解[awesome-java-leetcode][ajl]
46+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解[awesome-java-leetcode][ajl]
4747

4848

4949

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp