【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};
}
};
参考
Leetcode_easy_806. Number of Lines To Write String;
Grandyang;
完
转载于//www.cnblogs.com/happyamyhope/p/11214687.html
还没有评论,来说两句吧...