Skip to content

Latest commit

 

History

History
48 lines (26 loc) · 604 Bytes

0422._Valid_Word_Square.md

File metadata and controls

48 lines (26 loc) · 604 Bytes

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