Java solution


  • 0
    Q

    The idea is to find the diagonal symmetric char for each char

    public class Solution {
        public boolean validWordSquare(List<String> words) {
            for(int i = 0; i < words.size() ; i++){
                for(int j = 0; j < words.get(i).length(); j++){
                    if(j >= words.size()) return false;
                    String wa = words.get(i);
                    String wb = words.get(j);
                    if(wa.length() <= j && wb.length() <= i) continue;
                    else if(wa.length() <= j || wb.length() <= i) return false;
                    else if(wa.charAt(j) != wb.charAt(i)) return false;
                }
            }
            return true;
        }
    }
    

Log in to reply
 

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