Number of Lines To Write String LeetCode solution in Java

1
class Solution {
2
public int[] numberOfLines(int[] widths, String s) {
3
int sum = 0, count = 0;
4
for (int j = 0; j < s.length(); j++) {
5
int pos = s.charAt(j) - 'a';
6
sum += widths[pos];
7
if (sum > 100) {
8
j--;
9
count++;
10
sum = 0;
11
continue;
12
}
13
}
14
int[] arr = new int[2];
15
arr[0] = count + 1;
16
arr[1] = sum;
17
return arr;
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0