Posted on

Description

Submission

class Solution {
public:
    int wordsTyping(vector<string>& sentence, int rows, int cols) {
        string str;

        for(auto& word: sentence) {
            if(word.length() > cols) return 0;
            str += word + " ";
        }

        int idx = 0;
        for(int i = 0; i < rows; ++i) {
            idx += cols;
            while(str[idx%str.length()] != ' ') --idx;
            idx += 1;
        }
        return idx / str.length();
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *