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