Valid Word Square

http://www.lintcode.com/zh-cn/problem/valid-word-square/

public class Solution {
    /**
     * @param words: a list of string
     * @return: a boolean
     */
    public boolean validWordSquare(String[] words) {
        // Write your code here
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            for (int j = 0; j < words.length; j++) {
                if (word.charAt(j) == words[j].charAt(i)) {
                    continue;
                }
                return false;
            }
        }
        return true;
    }
}

你可能感兴趣的:(Valid Word Square)