JAVA_Number of Lines To Write String_LeetCode 806


JAVA_Number of Lines To Write String_LeetCode 806

JAVA_Number of Lines To Write String_LeetCode 806 풀이 class Solution { public int[] numberOfLines(int[] widths, String s) { int res = 1, pixel = 0; for (char c : s.toCharArray()) { int width = widths[c - 'a']; res = pixel + width > 100 ? res + 1 : res; pixel = pixel + width > 100 ? width : pixel + width; } return new int[] {res, pixel}; } } width의 값들은 각 알파벳의 너비값을 의미, pixel은 최대 100까지 됨 예제2에서 알 수 있듯이 a는 4를 의미하는데, bbbcccddd까지 90pixel, aa 까지 하면 98pixel이므로, 다시 시작하도록 함 * 출처 Number of Lines To Write Str...


#JAVA #JAVA_LeetCode806 #JAVA_NumberofLinesToWriteString #JAVA_NumberofLinesToWriteString_LeetCode806 #NumberofLinesToWriteString_LeetCode806

원문링크 : JAVA_Number of Lines To Write String_LeetCode 806