Please add this test case


  • 0
    U

    Another test case to add "aaaaaa1234567890123Ubefg".
    My solution was accepted but got wrong answer for this test case.

      public class Solution {
           public int strongPasswordChecker(String s) {
           int lower = 0;
           int upper = 0;
           int digits = 0;
           int count = 1;
           int change = 0;
           int r1=0;
           int r2=0;
    
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)>='A' && s.charAt(i) <= 'Z')  {
                upper++;
            } else if(s.charAt(i)>='a' && s.charAt(i) <='z') {
                lower++;
            } else if(s.charAt(i)>='0' && s.charAt(i) <= '9') {
                digits++;
            }
            if(i+1<s.length() && s.charAt(i)==s.charAt(i+1)){
                count++;
            }else{
                if(count>=3){
                    if (count %3 ==0){
                        r1++;
                    }else if (count %3 ==1){
                        r2++;
                    }
                    change += count/3;
                }
                count = 1;
            }
        }
        int add = 0;
        add += upper==0?1:0;
        add += lower==0?1:0;
        add += digits==0?1:0;
        if(s.length()+add < 6)
            add=6-s.length();
    
        int delete = 0;
        if(s.length()>20)
            delete = s.length()-20;
    
        System.out.println(change+" "+r1+" "+r2);
        int tmp=delete;
        // 1:1 replace "change" with "delete"
        if(tmp>0){
            change-=Math.min(r1, tmp);
            tmp=Math.max(0, tmp-r1);
        }
        // 1:2 replace "change" with "delete"
        if(tmp>0){
            change-=Math.min(r2, tmp/2);
            tmp=Math.max(0, tmp-r2*2);
        }
        // 1:3 replace "change" with "delete"
        /*if(tmp>0){
            change-=Math.min(change, tmp/3);
            tmp=Math.max(0, tmp-change*3);
        }*/
        // 1:1 replace "change" with "add"
        if(add>0){
            change-=Math.min(change,add);
        }
        return delete+change+add;
    }
    

    }


  • 0

    @username.1234 Done. Thanks.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.