4-line Python, easy to understand


  • 0
    J

    Just apply the problem statement directly - check if each row i is the same as each column j for j = i.

    def validWordSquare(self, words):
        return all(row == self.col(words, i) for i, row in enumerate(words))
    
    def col(self, words, j):
        return ''.join(word[j] for word in words if j < len(word))
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.