leetcode 2437

簡介

簡單題

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;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章