简介

简单题

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;
    }
}
posted on 2022-11-05 09:46  HDU李少帅  阅读(20)  评论(0编辑  收藏  举报