解答
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;
}
};
原文地址:https://www.cnblogs.com/cs-niaocai/p/9085726.html
时间: 2024-10-08 15:38:37