LeetCode 422 Valid Word Square

LeetCode 422 Valid Word Square Problem

Download Code
class Solution(object):
    def validWordSquare(self, words):
        :type words: List[str]
        :rtype: bool
        if words is None or len(words) == 0:
            return True
        ls = len(words)
        for i in range(ls):
            for j in range(1, len(words[i])):
                if j >= ls:
                    return False
                if i >= len(words[j]):
                    return False
                if words[i][j] != words[j][i]:
                    return False
        return True

    # def validWordSquare(self, words):
    #     # https://discuss.leetcode.com/topic/63423/1-liner-python/2
    #     # The map(None, ...) transposes the "matrix", filling missing spots with None
    #     return map(None, *words) == map(None, *map(None, *words))
Download Valid Word Square.py

List of all Valid Word Square problems

Leetcode 422 Valid Word Square problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.