Very Concise Java Solution, and easy to understand and fast


  • 2
    V
     public class Solution {
         public boolean validWordSquare(List<String> words) {
                if(words == null) return false;
                if(words.size() <= 1) return true;
        
                for(int i = 0; i < words.size(); i++)
                {
                       String s = words.get(i);
                       for(int j = 0; j < s.length(); j++)
                       {
                             try
                             {
                                   if(s.charAt(j) != words.get(j).charAt(i)) return false;
                             }
                             catch(Exception e)
                             {
                                   return false;
                             }
                       }
               }
        
             return true;
       }
    

    }


Log in to reply
 

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