Skip to content

422 Valid Word Square

422. Valid Word Square

题目: https://leetcode.com/problems/valid-word-square/

难度 : Easy

思路:

就是对比一个矩阵内 xy == yx?

try /except 真是好用

AC代码

class Solution(object):
    def validWordSquare(self, words):
        """
        :type words: List[str]
        :rtype: bool
        """
        n = len(words)
        for i in xrange(n):
            m = len(words[i])
            for j in xrange(m):
                try:
                    if words[i][j] != words[j][i]:
                        return False
                except:
                    return False
        return True


回到顶部