Leetcode 824 Solution
This article provides solution to leetcode question 824 (number-of-lines-to-write-string)
Access this page by simply typing in "lcs 824" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/number-of-lines-to-write-string
Solution
class Solution {
public:
vector<int> numberOfLines(vector<int>& widths, string S) {
int line_cnt = 1;
int line_left = 100;
for (auto ch: S)
{
auto width = widths[ch - 'a'];
if (width > line_left)
{
line_cnt++;
line_left = 100;
}
line_left -= width;
}
return {line_cnt, 100 - line_left};
}
};