• 문제 링크
Number of Lines To Write String - LeetCode
Can you solve this real interview question? Number of Lines To Write String - You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of
leetcode.com
• 풀이 코드
public class Solution {
public int[] numberOfLines(int[] widths, String s) {
int l = 1, w = 0;
for (char c : s.toCharArray()) {
int n = widths[c - 'a'];
if (w + n > 100) {
l++;
w = n;
} else w += n;
}
return new int[]{l, w};
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 819. Most Common Word - Java (0) | 2026.10.19 |
|---|---|
| [LeetCode] 812. Largest Triangle Area - Java (0) | 2026.10.18 |
| [LeetCode] 804. Unique Morse Code Words - Java (0) | 2026.10.16 |
| [LeetCode] 796. Rotate String - Java (0) | 2026.10.15 |
| [LeetCode] 783. Minimum Distance Between BST Nodes - Java (0) | 2026.10.14 |
댓글