简介
简单题
code
class Solution {
public Integer count = 0;
public void dfs(StringBuffer time, int [] aws, int rlt, int maxNumber){
if(rlt >= maxNumber) return;
int rltc = rlt;
for(int i=0; i<time.length(); i++){
if(aws[i] == 0){
int a = rlt % 10;
rlt = rlt/10;
time.setCharAt(i, (char)('0' + a));
}
}
if( "00".compareTo(time.substring(0,2)) <= 0 && time.substring(0,2).toString().compareTo("23") <= 0
&& "00".compareTo(time.substring(3)) <= 0 && time.substring(3).toString().compareTo("59") <= 0
) {
count++;
}
dfs(time, aws, rltc + 1, maxNumber);
}
public int countTime(String time) {
StringBuffer s = new StringBuffer(time);
int [] aws = new int[]{-1,-1,-1,-1, -1};
int countDefuse = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) - '?' == 0){
aws[i] = 0;
countDefuse++;
}
}
dfs(new StringBuffer(time), aws, 0, new Double(Math.pow(10, countDefuse)).intValue());
return count;
}
}
标签:maxNumber,int,2437,public,rlt,leetcode
From: https://www.cnblogs.com/eat-too-much/p/16859692.html