forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_806.java
22 lines (21 loc) · 783 Bytes
/
_806.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.fishercoder.solutions;
public class _806 {
public static class Solution1 {
public int[] numberOfLines(int[] widths, String S) {
int numOfLines = 1;
int offsetInCurrentLine = 0;
for (char c : S.toCharArray()) {
if (offsetInCurrentLine + widths[c - 'a'] < 100) {
offsetInCurrentLine += widths[c - 'a'];
} else if (offsetInCurrentLine + widths[c - 'a'] == 100) {
numOfLines++;
offsetInCurrentLine = 0;
} else {
numOfLines++;
offsetInCurrentLine = widths[c - 'a'];
}
}
return new int[]{numOfLines, offsetInCurrentLine};
}
}
}