【Leetcode_easy】806. Number of Lines To Write String

悠悠 2021-12-03 04:17 233阅读 0赞

problem

806. Number of Lines To Write String

solution:

  1. class Solution {
  2. public:
  3. vector<int> numberOfLines(vector<int>& widths, string S) {
  4. int line = 1, len = 0;
  5. for(auto ch:S)
  6. {
  7. int t = widths[ch-'a'];
  8. if(len+t>100) line++;
  9. len = (len+t>100) ? t : len+t;
  10. }
  11. return {line, len};
  12. }
  13. };

参考

  1. Leetcode_easy_806. Number of Lines To Write String;

  2. Grandyang;

转载于:https://www.cnblogs.com/happyamyhope/p/11214687.html

发表评论

表情:
评论列表 (有 0 条评论,233人围观)

还没有评论,来说两句吧...

相关阅读