Skip to content

Commit 63ac6fe

Browse files
committed
style: format code and document
1 parent bd309bf commit 63ac6fe

File tree

87 files changed

+124
-101
lines changed

Some content is hidden

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

87 files changed

+124
-101
lines changed

lcci/17.08.Circus Tower/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Solution {
105105
int n = height.length;
106106
int[][] arr = new int[n][2];
107107
for (int i = 0; i < n; ++i) {
108-
arr[i] = new int[]{height[i], weight[i]};
108+
arr[i] = new int[] {height[i], weight[i]};
109109
}
110110
Arrays.sort(arr, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
111111
Set<Integer> s = new HashSet<>();

lcci/17.08.Circus Tower/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Solution {
9494
int n = height.length;
9595
int[][] arr = new int[n][2];
9696
for (int i = 0; i < n; ++i) {
97-
arr[i] = new int[]{height[i], weight[i]};
97+
arr[i] = new int[] {height[i], weight[i]};
9898
}
9999
Arrays.sort(arr, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
100100
Set<Integer> s = new HashSet<>();

lcci/17.08.Circus Tower/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public int bestSeqAtIndex(int[] height, int[] weight) {
2929
int n = height.length;
3030
int[][] arr = new int[n][2];
3131
for (int i = 0; i < n; ++i) {
32-
arr[i] = new int[]{height[i], weight[i]};
32+
arr[i] = new int[] {height[i], weight[i]};
3333
}
3434
Arrays.sort(arr, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
3535
Set<Integer> s = new HashSet<>();

solution/0400-0499/0480.Sliding Window Median/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ class MedianFinder {
219219
}
220220
}
221221

222-
223222
class Solution {
224223
public double[] medianSlidingWindow(int[] nums, int k) {
225224
MedianFinder finder = new MedianFinder(k);

solution/0400-0499/0480.Sliding Window Median/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ class MedianFinder {
191191
}
192192
}
193193

194-
195194
class Solution {
196195
public double[] medianSlidingWindow(int[] nums, int k) {
197196
MedianFinder finder = new MedianFinder(k);

solution/0400-0499/0480.Sliding Window Median/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class MedianFinder {
4343
int largeSize = 0;
4444
int k;
4545

46-
template<typename T>
46+
template <typename T>
4747
void prune(T& pq) {
4848
while (!pq.empty() && delayed[pq.top()]) {
4949
if (--delayed[pq.top()] == 0) {

solution/0400-0499/0480.Sliding Window Median/Solution.java

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ private void rebalance() {
6565
}
6666
}
6767

68-
6968
class Solution {
7069
public double[] medianSlidingWindow(int[] nums, int k) {
7170
MedianFinder finder = new MedianFinder(k);

solution/0500-0599/0514.Freedom Trail/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ class Solution {
121121
for (int i = 1; i < m; ++i) {
122122
for (int j : pos[key.charAt(i) - 'a']) {
123123
for (int k : pos[key.charAt(i - 1) - 'a']) {
124-
f[i][j] = Math.min(f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
124+
f[i][j] = Math.min(
125+
f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
125126
}
126127
}
127128
}

solution/0500-0599/0514.Freedom Trail/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class Solution {
9393
for (int i = 1; i < m; ++i) {
9494
for (int j : pos[key.charAt(i) - 'a']) {
9595
for (int k : pos[key.charAt(i - 1) - 'a']) {
96-
f[i][j] = Math.min(f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
96+
f[i][j] = Math.min(
97+
f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
9798
}
9899
}
99100
}

solution/0500-0599/0514.Freedom Trail/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Solution {
1414
for (int i = 1; i < m; ++i) {
1515
for (int j : pos[key[i] - 'a']) {
1616
for (int k : pos[key[i - 1] - 'a']) {
17-
f[i][j] = min(f[i][j], f[i - 1][k] + min(abs(j - k), n - abs(j - k)) + 1);
17+
f[i][j] = min(f[i][j], f[i - 1][k] + min(abs(j - k), n - abs(j - k)) + 1);
1818
}
1919
}
2020
}

solution/0500-0599/0514.Freedom Trail/Solution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public int findRotateSteps(String ring, String key) {
1717
for (int i = 1; i < m; ++i) {
1818
for (int j : pos[key.charAt(i) - 'a']) {
1919
for (int k : pos[key.charAt(i - 1) - 'a']) {
20-
f[i][j] = Math.min(f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
20+
f[i][j] = Math.min(
21+
f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
2122
}
2223
}
2324
}

solution/0600-0699/0665.Non-decreasing Array/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public boolean checkPossibility(int[] nums) {
1414
}
1515
return true;
1616
}
17-
17+
1818
private boolean isSorted(int[] nums) {
1919
for (int i = 0; i < nums.length - 1; ++i) {
2020
if (nums[i] > nums[i + 1]) {

solution/0800-0899/0842.Split Array into Fibonacci Sequence/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class Solution {
127127
break;
128128
}
129129
x = x * 10 + num.charAt(j) - '0';
130-
if (x > Integer.MAX_VALUE || (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
130+
if (x > Integer.MAX_VALUE
131+
|| (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
131132
break;
132133
}
133134
if (ans.size() < 2 || x == ans.get(ans.size() - 1) + ans.get(ans.size() - 2)) {

solution/0800-0899/0842.Split Array into Fibonacci Sequence/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class Solution {
106106
break;
107107
}
108108
x = x * 10 + num.charAt(j) - '0';
109-
if (x > Integer.MAX_VALUE || (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
109+
if (x > Integer.MAX_VALUE
110+
|| (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
110111
break;
111112
}
112113
if (ans.size() < 2 || x == ans.get(ans.size() - 1) + ans.get(ans.size() - 2)) {

solution/0800-0899/0842.Split Array into Fibonacci Sequence/Solution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ private boolean dfs(int i) {
1818
break;
1919
}
2020
x = x * 10 + num.charAt(j) - '0';
21-
if (x > Integer.MAX_VALUE || (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
21+
if (x > Integer.MAX_VALUE
22+
|| (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
2223
break;
2324
}
2425
if (ans.size() < 2 || x == ans.get(ans.size() - 1) + ans.get(ans.size() - 2)) {

solution/0800-0899/0879.Profitable Schemes/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ class Solution {
106106
for (int k = 0; k <= minProfit; ++k) {
107107
f[i][j][k] = f[i - 1][j][k];
108108
if (j >= group[i - 1]) {
109-
f[i][j][k] = (f[i][j][k] + f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])]) % mod;
109+
f[i][j][k]
110+
= (f[i][j][k]
111+
+ f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])])
112+
% mod;
110113
}
111114
}
112115
}

solution/0800-0899/0879.Profitable Schemes/README_EN.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ class Solution {
8080
for (int k = 0; k <= minProfit; ++k) {
8181
f[i][j][k] = f[i - 1][j][k];
8282
if (j >= group[i - 1]) {
83-
f[i][j][k] = (f[i][j][k] + f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])]) % mod;
83+
f[i][j][k]
84+
= (f[i][j][k]
85+
+ f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])])
86+
% mod;
8487
}
8588
}
8689
}

solution/0800-0899/0879.Profitable Schemes/Solution.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ public int profitableSchemes(int n, int minProfit, int[] group, int[] profit) {
1111
for (int k = 0; k <= minProfit; ++k) {
1212
f[i][j][k] = f[i - 1][j][k];
1313
if (j >= group[i - 1]) {
14-
f[i][j][k] = (f[i][j][k] + f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])]) % mod;
14+
f[i][j][k]
15+
= (f[i][j][k]
16+
+ f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])])
17+
% mod;
1518
}
1619
}
1720
}

solution/1000-1099/1000.Minimum Cost to Merge Stones/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Solution {
122122
int[][][] f = new int[n + 1][n + 1][K + 1];
123123
final int inf = 1 << 20;
124124
for (int[][] g : f) {
125-
for(int[] e : g) {
125+
for (int[] e : g) {
126126
Arrays.fill(e, inf);
127127
}
128128
}

solution/1000-1099/1000.Minimum Cost to Merge Stones/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Solution {
9494
int[][][] f = new int[n + 1][n + 1][K + 1];
9595
final int inf = 1 << 20;
9696
for (int[][] g : f) {
97-
for(int[] e : g) {
97+
for (int[] e : g) {
9898
Arrays.fill(e, inf);
9999
}
100100
}

solution/1000-1099/1000.Minimum Cost to Merge Stones/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public int mergeStones(int[] stones, int K) {
1111
int[][][] f = new int[n + 1][n + 1][K + 1];
1212
final int inf = 1 << 20;
1313
for (int[][] g : f) {
14-
for(int[] e : g) {
14+
for (int[] e : g) {
1515
Arrays.fill(e, inf);
1616
}
1717
}

solution/1000-1099/1030.Matrix Cells in Distance Order/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ import java.util.Deque;
9999
class Solution {
100100
public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
101101
Deque<int[]> q = new ArrayDeque<>();
102-
q.offer(new int[]{rCenter, cCenter});
102+
q.offer(new int[] {rCenter, cCenter});
103103
boolean[][] vis = new boolean[rows][cols];
104104
vis[rCenter][cCenter] = true;
105105
int[][] ans = new int[rows * cols][2];
@@ -113,7 +113,7 @@ class Solution {
113113
int x = p[0] + dirs[k], y = p[1] + dirs[k + 1];
114114
if (x >= 0 && x < rows && y >= 0 && y < cols && !vis[x][y]) {
115115
vis[x][y] = true;
116-
q.offer(new int[]{x, y});
116+
q.offer(new int[] {x, y});
117117
}
118118
}
119119
}

solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import java.util.Deque;
8181
class Solution {
8282
public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
8383
Deque<int[]> q = new ArrayDeque<>();
84-
q.offer(new int[]{rCenter, cCenter});
84+
q.offer(new int[] {rCenter, cCenter});
8585
boolean[][] vis = new boolean[rows][cols];
8686
vis[rCenter][cCenter] = true;
8787
int[][] ans = new int[rows * cols][2];
@@ -95,7 +95,7 @@ class Solution {
9595
int x = p[0] + dirs[k], y = p[1] + dirs[k + 1];
9696
if (x >= 0 && x < rows && y >= 0 && y < cols && !vis[x][y]) {
9797
vis[x][y] = true;
98-
q.offer(new int[]{x, y});
98+
q.offer(new int[] {x, y});
9999
}
100100
}
101101
}

solution/1000-1099/1030.Matrix Cells in Distance Order/Solution.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Solution {
44
public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
55
Deque<int[]> q = new ArrayDeque<>();
6-
q.offer(new int[]{rCenter, cCenter});
6+
q.offer(new int[] {rCenter, cCenter});
77
boolean[][] vis = new boolean[rows][cols];
88
vis[rCenter][cCenter] = true;
99
int[][] ans = new int[rows * cols][2];
@@ -17,7 +17,7 @@ public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
1717
int x = p[0] + dirs[k], y = p[1] + dirs[k + 1];
1818
if (x >= 0 && x < rows && y >= 0 && y < cols && !vis[x][y]) {
1919
vis[x][y] = true;
20-
q.offer(new int[]{x, y});
20+
q.offer(new int[] {x, y});
2121
}
2222
}
2323
}

solution/1000-1099/1033.Moving Stones Until Consecutive/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Solution {
9292
mi = y - x < 3 || z - y < 3 ? 1 : 2;
9393
mx = z - x - 2;
9494
}
95-
return new int[]{mi, mx};
95+
return new int[] {mi, mx};
9696
}
9797
}
9898
```

solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Solution {
8181
mi = y - x < 3 || z - y < 3 ? 1 : 2;
8282
mx = z - x - 2;
8383
}
84-
return new int[]{mi, mx};
84+
return new int[] {mi, mx};
8585
}
8686
}
8787
```

solution/1000-1099/1033.Moving Stones Until Consecutive/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public int[] numMovesStones(int a, int b, int c) {
88
mi = y - x < 3 || z - y < 3 ? 1 : 2;
99
mx = z - x - 2;
1010
}
11-
return new int[]{mi, mx};
11+
return new int[] {mi, mx};
1212
}
1313
}

solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ class Solution {
211211
int j = i + l - 1;
212212
f[i][j] = 1 << 30;
213213
for (int k = i + 1; k < j; ++k) {
214-
f[i][j] = Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
214+
f[i][j]
215+
= Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
215216
}
216217
}
217218
}

solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ class Solution {
145145
int j = i + l - 1;
146146
f[i][j] = 1 << 30;
147147
for (int k = i + 1; k < j; ++k) {
148-
f[i][j] = Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
148+
f[i][j]
149+
= Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
149150
}
150151
}
151152
}

solution/1100-1199/1101.The Earliest Moment When Everyone Become Friends/Solution.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Solution {
22
private int[] p;
3-
3+
44
public int earliestAcq(int[][] logs, int n) {
55
Arrays.sort(logs, (a, b) -> a[0] - b[0]);
66
p = new int[n];
@@ -19,7 +19,7 @@ public int earliestAcq(int[][] logs, int n) {
1919
}
2020
return -1;
2121
}
22-
22+
2323
private int find(int x) {
2424
if (p[x] != x) {
2525
p[x] = find(p[x]);

solution/1100-1199/1109.Corporate Flight Bookings/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class Solution {
151151
public int[] corpFlightBookings(int[][] bookings, int n) {
152152
BinaryIndexedTree tree = new BinaryIndexedTree(n);
153153
for (var e : bookings) {
154-
int first =e[0], last = e[1], seats = e[2];
154+
int first = e[0], last = e[1], seats = e[2];
155155
tree.update(first, seats);
156156
tree.update(last + 1, -seats);
157157
}

solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class Solution {
121121
public int[] corpFlightBookings(int[][] bookings, int n) {
122122
BinaryIndexedTree tree = new BinaryIndexedTree(n);
123123
for (var e : bookings) {
124-
int first =e[0], last = e[1], seats = e[2];
124+
int first = e[0], last = e[1], seats = e[2];
125125
tree.update(first, seats);
126126
tree.update(last + 1, -seats);
127127
}

solution/1300-1399/1301.Number of Paths with Max Score/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class Solution {
138138
}
139139

140140
private void update(int i, int j, int x, int y) {
141-
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X' || board.get(i).charAt(j) == 'S') {
141+
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X'
142+
|| board.get(i).charAt(j) == 'S') {
142143
return;
143144
}
144145
if (f[x][y] > f[i][j]) {

solution/1300-1399/1301.Number of Paths with Max Score/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class Solution {
117117
}
118118

119119
private void update(int i, int j, int x, int y) {
120-
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X' || board.get(i).charAt(j) == 'S') {
120+
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X'
121+
|| board.get(i).charAt(j) == 'S') {
121122
return;
122123
}
123124
if (f[x][y] > f[i][j]) {

solution/1300-1399/1301.Number of Paths with Max Score/Solution.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public int[] pathsWithMaxScore(List<String> board) {
3737
}
3838

3939
private void update(int i, int j, int x, int y) {
40-
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X' || board.get(i).charAt(j) == 'S') {
40+
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X'
41+
|| board.get(i).charAt(j) == 'S') {
4142
return;
4243
}
4344
if (f[x][y] > f[i][j]) {

solution/1300-1399/1338.Reduce Array Size to The Half/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Solution {
8787
Arrays.sort(cnt);
8888
int ans = 0;
8989
int m = 0;
90-
for (int i = mx; ; --i) {
90+
for (int i = mx;; --i) {
9191
if (cnt[i] > 0) {
9292
m += cnt[i];
9393
++ans;

solution/1300-1399/1338.Reduce Array Size to The Half/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Solution {
7171
Arrays.sort(cnt);
7272
int ans = 0;
7373
int m = 0;
74-
for (int i = mx; ; --i) {
74+
for (int i = mx;; --i) {
7575
if (cnt[i] > 0) {
7676
m += cnt[i];
7777
++ans;

solution/1300-1399/1338.Reduce Array Size to The Half/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public int minSetSize(int[] arr) {
1111
Arrays.sort(cnt);
1212
int ans = 0;
1313
int m = 0;
14-
for (int i = mx; ; --i) {
14+
for (int i = mx;; --i) {
1515
if (cnt[i] > 0) {
1616
m += cnt[i];
1717
++ans;

0 commit comments

Comments
 (0)