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;
完