//url:https://leetcode.com/problems/number-of-lines-to-write-string/description/
class Solution {
public:
vector numberOfLines(vector& widths, string S) {
vector result;
int totalLine=0;
int totalLength=0;
for(int i=0;i100){
totalLine++;
totalLength=0;
}
totalLength+=widths[S[i]-‘a’];
}
if(totalLength>0){
totalLine++;
}
result.push_back(totalLine);
result.push_back(totalLength);
return result;
}
};
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2018/07/23/leetcode-806-number-of-lines-to-write-string/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!