Java solution beast 97.99%, without using map


  • 1
    A

    public class Solution {
    public String getHint(String secret, String guess) {
    char [] charS = secret.toCharArray();
    char [] charG = guess.toCharArray();
    int [] intS = new int[10];
    int [] intG = new int[10];
    int count1=0;
    int count =0;
    for(int i=0;i<charS.length;i++)
    {
    if(charS[i]==charG[i]) {count++;}
    else{
    intS[charS[i]-'0']++;
    intG[charG[i]-'0']++;
    }
    }
    for(int i=0;i<=9;i++){
    count1+=Math.min(intS[i],intG[i]);
    }

            String ret = "";
           
                ret+=(count+"A");
          
          
                ret+=(count1+"B");
            
            return ret;
        }
    

    }


Log in to reply
 

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