def validWordSquare(self, words): """ :type words: List[str] :rtype: bool """ lenw = len(words) try: for i in range(lenw): lenj = len(words[i]) for j in range(lenj): if words[i][j] != words[j][i]: return False return True except IndexError: return False
@leakey For 5 sec I was shocked by the simplicity of the code :)
It belongs here: https://discuss.leetcode.com/category/551/valid-word-square
@feyhi Thank you. I just try a direct way to solve the problem :)
Just a different way to do the
def validWordSquare(self, words): try: return all(words[j][i] == c for i, word in enumerate(words) for j, c in enumerate(word)) except IndexError: return False
@StefanPochmann Wow, very neat. Thank you.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.