Python Solution using IndexError, no extra space


  • 3
    L
    class Solution(object):
        def validWordSquare(self, words):
            try:
                for i in xrange(len(words)):
                    for j in xrange(len(words[i])):
                        if words[i][j] != words[j][i]:
                            return False
                return True
            except IndexError:
                return False
            
    

Log in to reply
 

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