Python Solution using IndexError, no extra space

  • 3
    class Solution(object):
        def validWordSquare(self, words):
                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.