leetcode每日一题 806. 写字符串需要的行数
class Solution {
public int[] numberOfLines(int[] widths, String s) {
int[] result = new int[2];
result[0] = 1;
char[] arr = s.toCharArray();
for (char c : arr) {
if((result[1] += widths[c-'a']) > 100){
result[0]++;
result[1] = widths[c-'a'];
}
}
return result;
}
}


浙公网安备 33010602011771号