diff --git a/src/main/java/g3401_3500/s3407_substring_matching_pattern/Solution.java b/src/main/java/g3401_3500/s3407_substring_matching_pattern/Solution.java index f0eaa776c..acd8024e6 100644 --- a/src/main/java/g3401_3500/s3407_substring_matching_pattern/Solution.java +++ b/src/main/java/g3401_3500/s3407_substring_matching_pattern/Solution.java @@ -27,7 +27,9 @@ private int fun(String s, String k) { for (j = 0; j < m; j++) { char ch1 = s.charAt(j + i); char ch2 = k.charAt(j); - if (ch1 != ch2) break; + if (ch1 != ch2) { + break; + } } if (j == m) { return i + j; diff --git a/src/main/java/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.java b/src/main/java/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.java index 6d3fbfa85..56f0dc02b 100644 --- a/src/main/java/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.java +++ b/src/main/java/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.java @@ -9,26 +9,27 @@ public class Solution { public long maximumCoins(int[][] coins, int k) { Arrays.sort(coins, (a, b) -> a[0] - b[0]); int n = coins.length; - long res = 0, cur = 0; + long res = 0; + long cur = 0; for (int i = 0, j = 0; i < n; ++i) { while (j < n && coins[j][1] <= coins[i][0] + k - 1) { - cur += 1L * (coins[j][1] - coins[j][0] + 1) * coins[j][2]; + cur += (long) (coins[j][1] - coins[j][0] + 1) * coins[j][2]; j++; } if (j < n) { - long part = 1L * Math.max(0, coins[i][0] + k - 1 - coins[j][0] + 1) * coins[j][2]; + long part = (long) Math.max(0, coins[i][0] + k - 1 - coins[j][0] + 1) * coins[j][2]; res = Math.max(res, cur + part); } - cur -= 1L * (coins[i][1] - coins[i][0] + 1) * coins[i][2]; + cur -= (long) (coins[i][1] - coins[i][0] + 1) * coins[i][2]; } cur = 0; for (int i = 0, j = 0; i < n; ++i) { - cur += 1L * (coins[i][1] - coins[i][0] + 1) * coins[i][2]; + cur += (long) (coins[i][1] - coins[i][0] + 1) * coins[i][2]; while (coins[j][1] < coins[i][1] - k + 1) { - cur -= 1L * (coins[j][1] - coins[j][0] + 1) * coins[j][2]; + cur -= (long) (coins[j][1] - coins[j][0] + 1) * coins[j][2]; j++; } - long part = 1L * Math.max(0, coins[i][1] - k - coins[j][0] + 1) * coins[j][2]; + long part = (long) Math.max(0, coins[i][1] - k - coins[j][0] + 1) * coins[j][2]; res = Math.max(res, cur - part); } return res; diff --git a/src/main/java/g3401_3500/s3414_maximum_score_of_non_overlapping_intervals/Solution.java b/src/main/java/g3401_3500/s3414_maximum_score_of_non_overlapping_intervals/Solution.java index 6f1db3f96..bd28cda39 100644 --- a/src/main/java/g3401_3500/s3414_maximum_score_of_non_overlapping_intervals/Solution.java +++ b/src/main/java/g3401_3500/s3414_maximum_score_of_non_overlapping_intervals/Solution.java @@ -23,8 +23,11 @@ public int[] maximumWeight(List> intervals) { int l = 0, r = i - 1; while (l <= r) { int m = (l + r) >>> 1; - if (arr[m][1] < arr[i][0]) l = m + 1; - else r = m - 1; + if (arr[m][1] < arr[i][0]) { + l = m + 1; + } else { + r = m - 1; + } } p[i] = r; } @@ -43,9 +46,13 @@ class S { S[][] dp = new S[n][5]; Comparator cmp = (a, b) -> { - if (a.sum != b.sum) return a.sum > b.sum ? -1 : 1; + if (a.sum != b.sum) { + return a.sum > b.sum ? -1 : 1; + } for (int i = 0; i < Math.min(a.x.length, b.x.length); i++) { - if (a.x[i] != b.x[i]) return a.x[i] < b.x[i] ? -1 : 1; + if (a.x[i] != b.x[i]) { + return a.x[i] < b.x[i] ? -1 : 1; + } } return Integer.compare(a.x.length, b.x.length); }; @@ -68,8 +75,11 @@ class S { S ans = base; for (int k = 1; k <= 4; k++) { S candidate = dp[n - 1][k]; - if (ans.sum < candidate.sum) ans = candidate; - else if (ans.sum == candidate.sum && cmp.compare(ans, candidate) > 0) ans = candidate; + if (ans.sum < candidate.sum) { + ans = candidate; + } else if (ans.sum == candidate.sum && cmp.compare(ans, candidate) > 0) { + ans = candidate; + } } Arrays.sort(ans.x); return ans.x;