【Leetcode_easy】806. Number of Lines To Write String

problem

806. Number of Lines To Write String

solution:

class Solution {
public:
    vector<int> numberOfLines(vector<int>& widths, string S) {
        int line = 1, len = 0;
        for(auto ch:S)
        {
            int t = widths[ch-'a'];
            if(len+t>100) line++;
            len = (len+t>100) ? t : len+t;
        }
        return {line, len};
    }
};

 

参考

1. Leetcode_easy_806. Number of Lines To Write String;

2. Grandyang;

posted on 2019-07-19 17:37  鹅要长大  阅读(102)  评论(0编辑  收藏  举报

导航