Skip to content

[pull] main from doocs:main #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lcci/17.08.Circus Tower/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Solution {
int n = height.length;
int[][] arr = new int[n][2];
for (int i = 0; i < n; ++i) {
arr[i] = new int[]{height[i], weight[i]};
arr[i] = new int[] {height[i], weight[i]};
}
Arrays.sort(arr, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
Set<Integer> s = new HashSet<>();
Expand Down
2 changes: 1 addition & 1 deletion lcci/17.08.Circus Tower/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Solution {
int n = height.length;
int[][] arr = new int[n][2];
for (int i = 0; i < n; ++i) {
arr[i] = new int[]{height[i], weight[i]};
arr[i] = new int[] {height[i], weight[i]};
}
Arrays.sort(arr, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
Set<Integer> s = new HashSet<>();
Expand Down
2 changes: 1 addition & 1 deletion lcci/17.08.Circus Tower/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public int bestSeqAtIndex(int[] height, int[] weight) {
int n = height.length;
int[][] arr = new int[n][2];
for (int i = 0; i < n; ++i) {
arr[i] = new int[]{height[i], weight[i]};
arr[i] = new int[] {height[i], weight[i]};
}
Arrays.sort(arr, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
Set<Integer> s = new HashSet<>();
Expand Down
1 change: 0 additions & 1 deletion solution/0400-0499/0480.Sliding Window Median/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ class MedianFinder {
}
}


class Solution {
public double[] medianSlidingWindow(int[] nums, int k) {
MedianFinder finder = new MedianFinder(k);
Expand Down
1 change: 0 additions & 1 deletion solution/0400-0499/0480.Sliding Window Median/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class MedianFinder {
}
}


class Solution {
public double[] medianSlidingWindow(int[] nums, int k) {
MedianFinder finder = new MedianFinder(k);
Expand Down
2 changes: 1 addition & 1 deletion solution/0400-0499/0480.Sliding Window Median/Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MedianFinder {
int largeSize = 0;
int k;

template<typename T>
template <typename T>
void prune(T& pq) {
while (!pq.empty() && delayed[pq.top()]) {
if (--delayed[pq.top()] == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ private void rebalance() {
}
}


class Solution {
public double[] medianSlidingWindow(int[] nums, int k) {
MedianFinder finder = new MedianFinder(k);
Expand Down
3 changes: 2 additions & 1 deletion solution/0500-0599/0514.Freedom Trail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class Solution {
for (int i = 1; i < m; ++i) {
for (int j : pos[key.charAt(i) - 'a']) {
for (int k : pos[key.charAt(i - 1) - 'a']) {
f[i][j] = Math.min(f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
f[i][j] = Math.min(
f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion solution/0500-0599/0514.Freedom Trail/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Solution {
for (int i = 1; i < m; ++i) {
for (int j : pos[key.charAt(i) - 'a']) {
for (int k : pos[key.charAt(i - 1) - 'a']) {
f[i][j] = Math.min(f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
f[i][j] = Math.min(
f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion solution/0500-0599/0514.Freedom Trail/Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Solution {
for (int i = 1; i < m; ++i) {
for (int j : pos[key[i] - 'a']) {
for (int k : pos[key[i - 1] - 'a']) {
f[i][j] = min(f[i][j], f[i - 1][k] + min(abs(j - k), n - abs(j - k)) + 1);
f[i][j] = min(f[i][j], f[i - 1][k] + min(abs(j - k), n - abs(j - k)) + 1);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion solution/0500-0599/0514.Freedom Trail/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public int findRotateSteps(String ring, String key) {
for (int i = 1; i < m; ++i) {
for (int j : pos[key.charAt(i) - 'a']) {
for (int k : pos[key.charAt(i - 1) - 'a']) {
f[i][j] = Math.min(f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
f[i][j] = Math.min(
f[i][j], f[i - 1][k] + Math.min(Math.abs(j - k), n - Math.abs(j - k)) + 1);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion solution/0600-0699/0665.Non-decreasing Array/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public boolean checkPossibility(int[] nums) {
}
return true;
}

private boolean isSorted(int[] nums) {
for (int i = 0; i < nums.length - 1; ++i) {
if (nums[i] > nums[i + 1]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class Solution {
break;
}
x = x * 10 + num.charAt(j) - '0';
if (x > Integer.MAX_VALUE || (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
if (x > Integer.MAX_VALUE
|| (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
break;
}
if (ans.size() < 2 || x == ans.get(ans.size() - 1) + ans.get(ans.size() - 2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class Solution {
break;
}
x = x * 10 + num.charAt(j) - '0';
if (x > Integer.MAX_VALUE || (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
if (x > Integer.MAX_VALUE
|| (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
break;
}
if (ans.size() < 2 || x == ans.get(ans.size() - 1) + ans.get(ans.size() - 2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ private boolean dfs(int i) {
break;
}
x = x * 10 + num.charAt(j) - '0';
if (x > Integer.MAX_VALUE || (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
if (x > Integer.MAX_VALUE
|| (ans.size() >= 2 && x > ans.get(ans.size() - 1) + ans.get(ans.size() - 2))) {
break;
}
if (ans.size() < 2 || x == ans.get(ans.size() - 1) + ans.get(ans.size() - 2)) {
Expand Down
5 changes: 4 additions & 1 deletion solution/0800-0899/0879.Profitable Schemes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ class Solution {
for (int k = 0; k <= minProfit; ++k) {
f[i][j][k] = f[i - 1][j][k];
if (j >= group[i - 1]) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])]) % mod;
f[i][j][k]
= (f[i][j][k]
+ f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])])
% mod;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion solution/0800-0899/0879.Profitable Schemes/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class Solution {
for (int k = 0; k <= minProfit; ++k) {
f[i][j][k] = f[i - 1][j][k];
if (j >= group[i - 1]) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])]) % mod;
f[i][j][k]
= (f[i][j][k]
+ f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])])
% mod;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion solution/0800-0899/0879.Profitable Schemes/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public int profitableSchemes(int n, int minProfit, int[] group, int[] profit) {
for (int k = 0; k <= minProfit; ++k) {
f[i][j][k] = f[i - 1][j][k];
if (j >= group[i - 1]) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])]) % mod;
f[i][j][k]
= (f[i][j][k]
+ f[i - 1][j - group[i - 1]][Math.max(0, k - profit[i - 1])])
% mod;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Solution {
int[][][] f = new int[n + 1][n + 1][K + 1];
final int inf = 1 << 20;
for (int[][] g : f) {
for(int[] e : g) {
for (int[] e : g) {
Arrays.fill(e, inf);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Solution {
int[][][] f = new int[n + 1][n + 1][K + 1];
final int inf = 1 << 20;
for (int[][] g : f) {
for(int[] e : g) {
for (int[] e : g) {
Arrays.fill(e, inf);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public int mergeStones(int[] stones, int K) {
int[][][] f = new int[n + 1][n + 1][K + 1];
final int inf = 1 << 20;
for (int[][] g : f) {
for(int[] e : g) {
for (int[] e : g) {
Arrays.fill(e, inf);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import java.util.Deque;
class Solution {
public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
Deque<int[]> q = new ArrayDeque<>();
q.offer(new int[]{rCenter, cCenter});
q.offer(new int[] {rCenter, cCenter});
boolean[][] vis = new boolean[rows][cols];
vis[rCenter][cCenter] = true;
int[][] ans = new int[rows * cols][2];
Expand All @@ -113,7 +113,7 @@ class Solution {
int x = p[0] + dirs[k], y = p[1] + dirs[k + 1];
if (x >= 0 && x < rows && y >= 0 && y < cols && !vis[x][y]) {
vis[x][y] = true;
q.offer(new int[]{x, y});
q.offer(new int[] {x, y});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import java.util.Deque;
class Solution {
public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
Deque<int[]> q = new ArrayDeque<>();
q.offer(new int[]{rCenter, cCenter});
q.offer(new int[] {rCenter, cCenter});
boolean[][] vis = new boolean[rows][cols];
vis[rCenter][cCenter] = true;
int[][] ans = new int[rows * cols][2];
Expand All @@ -95,7 +95,7 @@ class Solution {
int x = p[0] + dirs[k], y = p[1] + dirs[k + 1];
if (x >= 0 && x < rows && y >= 0 && y < cols && !vis[x][y]) {
vis[x][y] = true;
q.offer(new int[]{x, y});
q.offer(new int[] {x, y});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Solution {
public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
Deque<int[]> q = new ArrayDeque<>();
q.offer(new int[]{rCenter, cCenter});
q.offer(new int[] {rCenter, cCenter});
boolean[][] vis = new boolean[rows][cols];
vis[rCenter][cCenter] = true;
int[][] ans = new int[rows * cols][2];
Expand All @@ -17,7 +17,7 @@ public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
int x = p[0] + dirs[k], y = p[1] + dirs[k + 1];
if (x >= 0 && x < rows && y >= 0 && y < cols && !vis[x][y]) {
vis[x][y] = true;
q.offer(new int[]{x, y});
q.offer(new int[] {x, y});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Solution {
mi = y - x < 3 || z - y < 3 ? 1 : 2;
mx = z - x - 2;
}
return new int[]{mi, mx};
return new int[] {mi, mx};
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Solution {
mi = y - x < 3 || z - y < 3 ? 1 : 2;
mx = z - x - 2;
}
return new int[]{mi, mx};
return new int[] {mi, mx};
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public int[] numMovesStones(int a, int b, int c) {
mi = y - x < 3 || z - y < 3 ? 1 : 2;
mx = z - x - 2;
}
return new int[]{mi, mx};
return new int[] {mi, mx};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class Solution {
int j = i + l - 1;
f[i][j] = 1 << 30;
for (int k = i + 1; k < j; ++k) {
f[i][j] = Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
f[i][j]
= Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class Solution {
int j = i + l - 1;
f[i][j] = 1 << 30;
for (int k = i + 1; k < j; ++k) {
f[i][j] = Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
f[i][j]
= Math.min(f[i][j], f[i][k] + f[k][j] + values[i] * values[k] * values[j]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Solution {
private int[] p;

public int earliestAcq(int[][] logs, int n) {
Arrays.sort(logs, (a, b) -> a[0] - b[0]);
p = new int[n];
Expand All @@ -19,7 +19,7 @@ public int earliestAcq(int[][] logs, int n) {
}
return -1;
}

private int find(int x) {
if (p[x] != x) {
p[x] = find(p[x]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Solution {
public int[] corpFlightBookings(int[][] bookings, int n) {
BinaryIndexedTree tree = new BinaryIndexedTree(n);
for (var e : bookings) {
int first =e[0], last = e[1], seats = e[2];
int first = e[0], last = e[1], seats = e[2];
tree.update(first, seats);
tree.update(last + 1, -seats);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Solution {
public int[] corpFlightBookings(int[][] bookings, int n) {
BinaryIndexedTree tree = new BinaryIndexedTree(n);
for (var e : bookings) {
int first =e[0], last = e[1], seats = e[2];
int first = e[0], last = e[1], seats = e[2];
tree.update(first, seats);
tree.update(last + 1, -seats);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class Solution {
}

private void update(int i, int j, int x, int y) {
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X' || board.get(i).charAt(j) == 'S') {
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X'
|| board.get(i).charAt(j) == 'S') {
return;
}
if (f[x][y] > f[i][j]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class Solution {
}

private void update(int i, int j, int x, int y) {
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X' || board.get(i).charAt(j) == 'S') {
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X'
|| board.get(i).charAt(j) == 'S') {
return;
}
if (f[x][y] > f[i][j]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public int[] pathsWithMaxScore(List<String> board) {
}

private void update(int i, int j, int x, int y) {
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X' || board.get(i).charAt(j) == 'S') {
if (x >= n || y >= n || f[x][y] == -1 || board.get(i).charAt(j) == 'X'
|| board.get(i).charAt(j) == 'S') {
return;
}
if (f[x][y] > f[i][j]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Solution {
Arrays.sort(cnt);
int ans = 0;
int m = 0;
for (int i = mx; ; --i) {
for (int i = mx;; --i) {
if (cnt[i] > 0) {
m += cnt[i];
++ans;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Solution {
Arrays.sort(cnt);
int ans = 0;
int m = 0;
for (int i = mx; ; --i) {
for (int i = mx;; --i) {
if (cnt[i] > 0) {
m += cnt[i];
++ans;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public int minSetSize(int[] arr) {
Arrays.sort(cnt);
int ans = 0;
int m = 0;
for (int i = mx; ; --i) {
for (int i = mx;; --i) {
if (cnt[i] > 0) {
m += cnt[i];
++ans;
Expand Down
Loading