标签:vector class stat int line syn solution ati lines
1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 vector<int> numberOfLines(vector<int>& widths, string S) 12 { 13 int count=1,length=0; 14 for(char c:S) 15 { 16 int cur=widths[c-‘a‘]; 17 if(cur+length<100) 18 { 19 length+=cur; 20 continue; 21 } 22 else if(cur+length==100) 23 { 24 count++; 25 length=0; 26 } 27 else 28 { 29 count++; 30 length=cur; 31 } 32 } 33 return {count,length}; 34 } 35 };
直接扫描,统计长度就行,问题不大
806. Number of Lines To Write String
标签:vector class stat int line syn solution ati lines
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9182132.html