Java solution which beats 94.58% solutions


  • 0
    M

    class Solution {
    public String[] findWords(String[] words) {
    String s1="QqWwEeRrTtUuIiOoPpYy";

        int flag=0;
       
        ArrayList<String> arr=new ArrayList<String>();
        String s2 = "aAsSdDfFgGhHjJkKlL"; 
        
         String s3 = "zZxXcCvVbBnNmM"; 
        
        for(int i=0;i<words.length;i++){
          
            for(char c : words[i].toCharArray()){
                           if(s1.indexOf(c) >= 0 ) 
                               flag=1;
                               else
                               {
                                   flag=0;
                                    break;
                               }
                         }
            
            if(flag==1)
                arr.add(words[i]);
            else{
            
                       for(char c : words[i].toCharArray()){       
                        if(s2.indexOf(c) >= 0 ) 
                               flag=1;
                               else
                               {
                                   flag=0;
                                   break;
                               }
                       }
                
            
                
                if(flag==1)
                    arr.add(words[i]);
                else{
                    
                     for(char c : words[i].toCharArray()){
                        if(s3.indexOf(c) >= 0 ) 
                               flag=1;
                               else
                               {
                                   flag=0;
                                   break;
                               }
                
                           }
                        
                    if(flag==1)
                    arr.add(words[i]);
                    
                }
                
                
                
            }
                     
             
        }
      
        String [] ans = arr.toArray(new String[arr.size()]);
        return ans;
    }
    

    }


Log in to reply
 

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