5 lines C++


  • 0
        string getVertical(vector<string>& words,int col){
            string s="";
            for(int i=0;i<words.size();i++) if(col<words[i].size()) s.push_back(words[i][col]);
            return s;
        }
        
        bool validWordSquare(vector<string>& words) {
            for(int i=0;i<words.size();i++) if(words[i]!=getVertical(words,i)) return false;
            return true;
        }
    

Log in to reply
 

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