7 lines in python, very easy to understand


  • 0
    J
    class Solution(object):
        def validWordSquare(self, words):
            """
            :type words: List[str]
            :rtype: bool
            """
            for i in range(len(words)):
                row_string = words[i]
                column_string = ''.join([word[i] for word in words if len(word) > i])
                if row_string != column_string:
                    return False
            else:
                return True
    

Log in to reply
 

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