Valid Word Square

主要是边界判断很麻烦,碰到这种原则就是横竖都必须去判,哪个都不能漏

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

        return True

results matching ""

    No results matching ""