422. Valid Word Square.md 604 字节
Newer Older
K
KEQI HUANG 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
### 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
```