kk
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user