首页 > 其他分享 >leetcode 2437

leetcode 2437

时间:2022-11-05 09:55:41浏览次数:40  
标签:maxNumber int 2437 public rlt leetcode

简介

简单题

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

相关文章

  • [LeetCode] 2131. Longest Palindrome by Concatenating Two Letter Words
    Youaregivenanarrayofstrings words.Eachelementof words consistsof two lowercaseEnglishletters.Createthe longestpossiblepalindrome bysele......
  • LeetCode刷题记录.Day6
    链表相交题目链接面试题02.07.链表相交-力扣(LeetCode)classSolution{public:ListNode*getIntersectionNode(ListNode*headA,ListNode*headB){......
  • leetcode Boyer-Moore 算法
    简介如何寻求一个数组中的出现次数最多的书虽然最开始想到了这个方法但是不知道如何去表达,grep就利用了这个算法classSolution{publicintmajorityElement(int[......
  • Leetcode刷题第二周
    链表:插入快,查询慢,存储不连续分为单链表,双链表和循环链表在链表中使用虚拟头结点,可以减少增删改查中对头结点的特殊处理移除链表元素203/***Definitionforsingly......
  • LeetCode 145. 二叉树的后序遍历
    问题描述给定一个二叉树,返回它的后序遍历。示例:进阶:递归算法很简单,你可以通过迭代算法完成吗?题目代码/***Definitionforabinarytreenode.*publicclassTre......
  • leetcode-2283-easy
    CheckifNumberHasEqualDigitCountandDigitValueYouaregivena0-indexedstringnumoflengthnconsistingofdigits.Returntrueifforeveryindexi......
  • leetcode-754-medium
    ReachaNumberYouarestandingatposition0onaninfinitenumberline.Thereisadestinationatpositiontarget.YoucanmakesomenumberofmovesnumMove......
  • leetcode-657-easy
    RobotReturntoOriginThereisarobotstartingattheposition(0,0),theorigin,ona2Dplane.Givenasequenceofitsmoves,judgeifthisrobotendsup......
  • leetcode-1417-easy
    ReformatTheStringYouaregivenanalphanumericstrings.(AlphanumericstringisastringconsistingoflowercaseEnglishlettersanddigits).Youhaveto......
  • leetcode-771-easy
    JewelsandStonesYou'regivenstringsjewelsrepresentingthetypesofstonesthatarejewels,andstonesrepresentingthestonesyouhave.Eachcharacterin......