806. Number of Lines To Write String (5月24日)

Posted cs-niaocai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了806. Number of Lines To Write String (5月24日)相关的知识,希望对你有一定的参考价值。

解答

class Solution {
public:
    vector<int> numberOfLines(vector<int>& widths, string S) {
        vector<int> result;
        int line=1,units=0;
        map<char,int> pairs;
        char c=‘a‘;
        for(int width:widths){
            pairs.insert(make_pair(c,width));
            ++c;
        }
        for(auto ch: S){
            units += pairs[ch];
            if(units > 100){
                 ++line;
                 units=pairs[ch];
            }
        }
        result.push_back(line);
        result.push_back(units);
        return result;
    }
};

以上是关于806. Number of Lines To Write String (5月24日)的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode&Python] Problem 806. Number of Lines To Write String

806. Number of Lines To Write String (5月24日)

LeetCode算法题-Number of Lines To Write String(Java实现)

[LeetCode] Number of Lines To Write String

leetCode题解之Number of Lines To Write String

Object Detection with 10 lines of code - Image AI