This commit is contained in:
kkunkka
2023-12-09 14:30:14 +08:00
parent 6c27b377f6
commit 4ccaaa2885
2 changed files with 58 additions and 1 deletions

View File

@@ -22,10 +22,42 @@ public class Solution {
temp -= cardPoints[i - len];
temp += cardPoints[i];
if (temp < max) {
max =temp;
max = temp;
}
}
return sum - max;
}
// 2048. 下一个更大的数值平衡数
public int nextBeautifulNumber(int n) {
while(!ok(++n)) {
}
return n;
}
private boolean ok(int n){
if (n==0) {
return false;
}
int[] dp = new int[10];
while (n!=0) {
int t = n%10;
dp[t]++;
if (dp[t] > t) {
return false;
}
n/=10;
}
for (int i = 1; i < dp.length; i++) {
if (dp[i]!=0 && dp[i]!=i) {
return false;
}
}
return true;
}
}