Beats 100% JS


  • 0
    P
    /**
     * @param {string[]} words
     * @return {boolean}
     */
    var validWordSquare = function(words) {
        var i = 0;
        if(words[0].length!=words.length) return false;
        while(i<words.length) {
            if(words[i].length>words.length) return false;
            for(var k = 0; i+k<words.length; k++) {
                if(words[i+k][i]!=words[i][i+k]) {
                    return false;
                }
            }
            i++;
        }
        return true;
    };
    

Log in to reply
 

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