LeetCode—806. Number of Lines To Write String


//url:https://leetcode.com/problems/number-of-lines-to-write-string/description/

class Solution {
public:
    vector numberOfLines(vector& widths, string S) {
        vector result;
        int totalLine=0;
        int totalLength=0;
        for(int i=0;i100){
                totalLine++;
                totalLength=0;
            }
            totalLength+=widths[S[i]-'a'];
        }
        if(totalLength>0){
            totalLine++;
        }
        result.push_back(totalLine);
        result.push_back(totalLength);
        return result;
    }
};


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注