Skip to content

Commit a847b5a

Browse files
committed
update md files
1 parent da0430b commit a847b5a

File tree

7 files changed

+339
-5
lines changed

7 files changed

+339
-5
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
### [Array 数组](https://leetcode-cn.com/tag/array/)
2424

25-
| 题目名(点击跳转题目) | 笔记链接(点击跳转链接) | 难度评级 | 关键词 |
26-
| :----------------------------------------------------------: | :----------------------------------------------------------: | :------: | :----------------------: |
27-
| [628 . 三个数的最大乘积](https://leetcode-cn.com/problems/maximum-product-of-three-numbers/) | [628 . 三个数的最大乘积](https://github.com/dingjianhub/leetcode/blob/master/Notes/Array%20%E6%95%B0%E7%BB%84/628_MaximumProductOfThreeNumbers_%E4%B8%89%E4%B8%AA%E6%95%B0%E7%9A%84%E6%9C%80%E5%A4%A7%E4%B9%98%E7%A7%AF.md) | **Easy** | 分情况讨论;多个数字交换 |
28-
| | | | |
29-
| | | | |
25+
| 题目名(点击跳转题目) | 笔记链接(点击跳转链接) | 难度评级 | 关键词 |
26+
| :----------------------------------------------------------: | :----------------------------------------------------------: | :--------: | :----------------------: |
27+
| [628 . 三个数的最大乘积](https://leetcode-cn.com/problems/maximum-product-of-three-numbers/) | [628 . 三个数的最大乘积](https://github.com/dingjianhub/leetcode/blob/master/Notes/Array%20%E6%95%B0%E7%BB%84/628_MaximumProductOfThreeNumbers_%E4%B8%89%E4%B8%AA%E6%95%B0%E7%9A%84%E6%9C%80%E5%A4%A7%E4%B9%98%E7%A7%AF.md) | **Easy** | 分情况讨论;多个数字交换 |
28+
| [238 . 除自身以外的数组的乘积](https://leetcode-cn.com/problems/product-of-array-except-self/) | [238 . 除自身以外的数组的乘积](https://github.com/dingjianhub/leetcode/blob/master/Notes/Array%20%E6%95%B0%E7%BB%84/238_ProductOfArrayExceptSelf_%E9%99%A4%E8%87%AA%E8%BA%AB%E4%BB%A5%E5%A4%96%E7%9A%84%E6%95%B0%E7%BB%84%E7%9A%84%E4%B9%98%E7%A7%AF.md) | **Medium** | 前缀积;后缀积 |
29+
| | | | |
3030

3131

3232

@@ -75,6 +75,11 @@
7575
| [105 . 从前序与中序遍历序列构造二叉树](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | [105 . 从前序与中序遍历序列构造二叉树](https://github.com/dingjianhub/leetcode/blob/master/Notes/tree%20%E6%A0%91/105_ConstructBinaryTreeFromPreorderAndInorderTraversal_%E4%BB%8E%E5%89%8D%E5%BA%8F%E4%B8%8E%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BA%8F%E5%88%97%E6%9E%84%E9%80%A0%E4%BA%8C%E5%8F%89%E6%A0%91.md) | **Medium** | |
7676
| [106 . 从中序和后序遍历构造二叉树](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | [106 . 从中序和后序遍历构造二叉树](https://github.com/dingjianhub/leetcode/blob/master/Notes/tree%20%E6%A0%91/106_ConstructBinaryTreeFromInorderAndPostorderTraversal_%E4%BB%8E%E4%B8%AD%E5%BA%8F%E5%92%8C%E5%90%8E%E5%BA%8F%E9%81%8D%E5%8E%86%E6%9E%84%E9%80%A0%E4%BA%8C%E5%8F%89%E6%A0%91.md) | **Medium** | |
7777
| [1008 . 先序遍历二叉搜索树构造二叉树](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | [1008 . 先序遍历二叉搜索树构造二叉树](https://github.com/dingjianhub/leetcode/blob/master/Notes/tree%20%E6%A0%91/1008_ConstructBinarySearchTreeFromPreorderTraversal_%E5%85%88%E5%BA%8F%E9%81%8D%E5%8E%86%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E6%9E%84%E9%80%A0%E4%BA%8C%E5%8F%89%E6%A0%91.md) | **Medium** | |
78+
| [101 . 对称二叉树](https://leetcode-cn.com/problems/symmetric-tree/) | [101 . 对称二叉树](https://github.com/dingjianhub/leetcode/blob/master/Notes/tree%20%E6%A0%91/101_SymmetricTree_%E5%AF%B9%E7%A7%B0%E4%BA%8C%E5%8F%89%E6%A0%91.md) | **Easy** | DFS;BFS |
79+
| [104 . 二叉树的最大深度](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | [104 . 二叉树的最大深度](https://github.com/dingjianhub/leetcode/blob/master/Notes/tree%20%E6%A0%91/104_MaximumDepthOfBinaryTree_%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E5%A4%A7%E6%B7%B1%E5%BA%A6.md) | **Easy** | DFS;BFS |
80+
| [112 . 路径总和](https://leetcode-cn.com/problems/path-sum/) | [112 . 路径总和](https://github.com/dingjianhub/leetcode/blob/master/Notes/tree%20%E6%A0%91/112_PathSum_%E8%B7%AF%E5%BE%84%E6%80%BB%E5%92%8C.md) | **Easy** | DFS;BFS |
81+
| | | | |
82+
| | | | |
7883

7984

8085

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package ltd.ryantech.array.spiralMatrix54;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
/**
7+
* @author jerry
8+
* @program leetcode
9+
* @package_name ltd.ryantech.array.spiralMatrix54
10+
* @description 54. 螺旋矩阵
11+
* @leetcode_CN_url // https://leetcode-cn.com/problems/spiral-matrix/
12+
* @leetcode_US_url // https://leetcode.com/problems/spiral-matrix/
13+
* @hard_level Medium
14+
* @tag Array // https://leetcode-cn.com/tag/array/
15+
* @create 2020/06/05 11:38
16+
**/
17+
18+
public class Solution1 {
19+
public List<Integer> spiralOrder(int[][] matrix) {
20+
if (matrix.length == 0) {
21+
return new LinkedList<>();
22+
}
23+
24+
int row = matrix.length;
25+
int column = matrix[0].length;
26+
int resSize = row * column;
27+
int[][] visited = new int[row][column];
28+
List<Integer> ans = new LinkedList<>();
29+
int x = 0;
30+
int y = 0;
31+
int tot = 0;
32+
while (tot < resSize) {
33+
while (y < column && visited[x][y] == 0) {
34+
visited[x][y] = 1;
35+
ans.add(matrix[x][y]);
36+
tot++;
37+
y++;
38+
}
39+
y--; // 修正
40+
x++; // 换到下一行
41+
while (x < row && visited[x][y] == 0) {
42+
visited[x][y] = 1;
43+
ans.add(matrix[x][y]);
44+
tot++;
45+
x++;
46+
}
47+
x--; // 修正
48+
y--; // 换行
49+
while (y >= 0 && visited[x][y] == 0) {
50+
visited[x][y] = 1;
51+
ans.add(matrix[x][y]);
52+
tot++;
53+
y--;
54+
}
55+
y++; // 修正
56+
x--; // 换行
57+
while (x >= 0 && visited[x][y] == 0) {
58+
visited[x][y] = 1;
59+
ans.add(matrix[x][y]);
60+
tot++;
61+
x--;
62+
}
63+
x++; // 修正
64+
y++; // 换行
65+
}
66+
return ans;
67+
}
68+
69+
public static void main(String[] args) {
70+
// int[][] matrix = {};
71+
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
72+
List<Integer> ans = new Solution1().spiralOrder(matrix);
73+
for (int num : ans) {
74+
System.out.println(num);
75+
}
76+
}
77+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package ltd.ryantech.array.spiralMatrix54;
2+
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
6+
/**
7+
* @author jerry
8+
* @program leetcode
9+
* @package_name ltd.ryantech.array.spiralMatrix54
10+
* @description
11+
* @create 2020/06/05 13:15
12+
**/
13+
14+
public class Solution2 {
15+
public List<Integer> spiralOrder(int[][] matrix) {
16+
if (matrix.length == 0) {
17+
return new LinkedList<>();
18+
}
19+
20+
int row = matrix.length;
21+
int column = matrix[0].length;
22+
int resSize = row * column;
23+
int[][] visited = new int[row][column];
24+
List<Integer> ans = new LinkedList<>();
25+
int x = 0;
26+
int y = 0;
27+
int tot = 1;
28+
ans.add(matrix[x][y]);
29+
visited[x][y] = 1;
30+
while (tot < resSize) {
31+
while (y + 1 < column && visited[x][y + 1] == 0) {
32+
visited[x][++y] = 1;
33+
ans.add(matrix[x][y]);
34+
tot++;
35+
}
36+
while (x + 1 < row && visited[x + 1][y] == 0) {
37+
visited[++x][y] = 1;
38+
ans.add(matrix[x][y]);
39+
tot++;
40+
}
41+
while (y - 1 >= 0 && visited[x][y - 1] == 0) {
42+
visited[x][--y] = 1;
43+
ans.add(matrix[x][y]);
44+
tot++;
45+
}
46+
while (x - 1 >= 0 && visited[x - 1][y] == 0) {
47+
visited[--x][y] = 1;
48+
ans.add(matrix[x][y]);
49+
tot++;
50+
}
51+
}
52+
return ans;
53+
}
54+
55+
public static void main(String[] args) {
56+
// int[][] matrix = {};
57+
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
58+
List<Integer> ans = new Solution2().spiralOrder(matrix);
59+
for (int num : ans) {
60+
System.out.println(num);
61+
}
62+
}
63+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package ltd.ryantech.array.spiralMatrixii59;
2+
3+
/**
4+
* @author jerry
5+
* @program leetcode
6+
* @package_name ltd.ryantech.array.spiralMatrixii59
7+
* @description 59. 螺旋矩阵 II
8+
* @leetcode_CN_url // https://leetcode-cn.com/problems/spiral-matrix-ii/
9+
* @leetcode_US_url // https://leetcode.com/problems/spiral-matrix-ii/
10+
* @hard_level Medium
11+
* @tag Array // https://leetcode-cn.com/tag/array/
12+
* @create 2020/06/05 11:44
13+
**/
14+
15+
public class Solution1 {
16+
public int[][] generateMatrix(int n) {
17+
if (n <= 0) {
18+
return new int[][]{};
19+
}
20+
21+
int[][] ans = new int[n][n];
22+
int tot = 1;
23+
int row = 0;
24+
int column = 0;
25+
ans[row][column] = tot;
26+
while (tot < n * n) {
27+
while (column + 1 < n && ans[row][column + 1] == 0) {
28+
ans[row][++column] = ++tot;
29+
}
30+
while (row + 1 < n && ans[row + 1][column] == 0) {
31+
ans[++row][column] = ++tot;
32+
}
33+
while (column - 1 >= 0 && ans[row][column - 1] == 0) {
34+
ans[row][--column] = ++tot;
35+
}
36+
while (row - 1 >= 0 && ans[row - 1][column] == 0) {
37+
ans[--row][column] = ++tot;
38+
}
39+
}
40+
return ans;
41+
}
42+
43+
public static void main(String[] args) {
44+
int[][] res = new Solution1().generateMatrix(3);
45+
for (int[] nums : res) {
46+
for (int num : nums) {
47+
System.out.println(num);
48+
}
49+
}
50+
}
51+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ltd.ryantech.twoPointer.reverseString344;
2+
3+
/**
4+
* @author jerry
5+
* @program leetcode
6+
* @package_name ltd.ryantech.twoPointer.reverseString344
7+
* @description 344. 反转字符串
8+
* @leetcode_CN_url // https://leetcode-cn.com/problems/reverse-string/
9+
* @leetcode_US_url // https://leetcode.com/problems/reverse-string/
10+
* @hard_level Easy
11+
* @tag Two Pointer // https://leetcode-cn.com/tag/two-pointers/
12+
* @create 2020/06/04 20:04
13+
**/
14+
15+
public class Solution1 {
16+
public void reverseString(char[] s) {
17+
int left = 0;
18+
int right = s.length - 1;
19+
char t;
20+
while (left < right) {
21+
t = s[left];
22+
s[left] = s[right];
23+
s[right] = t;
24+
left++;
25+
right--;
26+
}
27+
}
28+
29+
public static void main(String[] args) {
30+
char[] s = {'h', 'e', 'l', 'l', 'o'};
31+
}
32+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package ltd.ryantech.twoPointer.reverseStringii541;
2+
3+
/**
4+
* @author jerry
5+
* @program leetcode
6+
* @package_name ltd.ryantech.twoPointer.reverseStringii541
7+
* @description 541. 反转字符串 II
8+
* @leetcode_CN_url // https://leetcode-cn.com/problems/reverse-string-ii/
9+
* @leetcode_US_url // https://leetcode.com/problems/reverse-string-ii/
10+
* @hard_level Easy
11+
* @tag Two Pointer // https://leetcode-cn.com/tag/two-pointers/
12+
* @create 2020/06/04 20:07
13+
**/
14+
15+
public class Solution1 {
16+
public String reverseStr(String s, int k) {
17+
StringBuilder stringBuilder = new StringBuilder();
18+
int lastReached = 0;
19+
int start = 0;
20+
int end = start;
21+
int stringLength = s.length();
22+
while (start < stringLength) {
23+
while ((end - start + 1) < k && end < stringLength - 1) {
24+
end++;
25+
}
26+
lastReached = end + k;
27+
if (lastReached < stringLength) {
28+
29+
}
30+
for (int i = end; i >= start; i--) {
31+
stringBuilder.append(s.charAt(i));
32+
}
33+
for (int i = end + 1; i <= lastReached; i++) {
34+
stringBuilder.append(s.charAt(i));
35+
}
36+
start = lastReached + 1;
37+
end = start;
38+
}
39+
return stringBuilder.toString();
40+
}
41+
42+
43+
public static void main(String[] args) {
44+
String s = "abcdefg";
45+
System.out.println(new Solution1().reverseStr(s, 4));
46+
}
47+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package ltd.ryantech.twoPointer.reverseVowelsOfAString345;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
/**
7+
* @author jerry
8+
* @program leetcode
9+
* @package_name ltd.ryantech.twoPointer.reverseVowelsOfAString345
10+
* @description 345. 反转字符串中的元音字母
11+
* @leetcode_CN_url // https://leetcode-cn.com/problems/reverse-vowels-of-a-string/
12+
* @leetcode_US_url // https://leetcode.com/problems/reverse-vowels-of-a-string/
13+
* @hard_level Easy
14+
* @tag Two Pointer // https://leetcode-cn.com/tag/two-pointers/
15+
* @create 2020/06/04 19:13
16+
**/
17+
18+
public class Solution1 {
19+
public String reverseVowels(String s) {
20+
int left = 0;
21+
int right = s.length() - 1;
22+
char[] s1 = s.toCharArray();
23+
Set<Character> set = new HashSet<>();
24+
set.add('a');
25+
set.add('e');
26+
set.add('i');
27+
set.add('o');
28+
set.add('u');
29+
set.add('A');
30+
set.add('E');
31+
set.add('I');
32+
set.add('O');
33+
set.add('U');
34+
char t;
35+
while (left < right) {
36+
while (left < right && !set.contains(s1[left])) {
37+
left++;
38+
}
39+
while (left < right && !set.contains(s1[right])) {
40+
right--;
41+
}
42+
t = s1[left];
43+
s1[left] = s1[right];
44+
s1[right] = t;
45+
left++;
46+
right--;
47+
}
48+
StringBuilder stringBuilder = new StringBuilder();
49+
for (char c : s1) {
50+
stringBuilder.append(c);
51+
}
52+
return stringBuilder.toString();
53+
}
54+
55+
public static void main(String[] args) {
56+
String s = "leetcode";
57+
System.out.println(new Solution1().reverseVowels(s));
58+
}
59+
}

0 commit comments

Comments
 (0)