Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22c13b7

Browse filesBrowse files
Add files via upload
1 parent 1f77cc1 commit 22c13b7
Copy full SHA for 22c13b7

File tree

1 file changed

+29
-0
lines changed
Filter options

1 file changed

+29
-0
lines changed
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Runtime: 0 ms, faster than 100.00% of C++ online submissions for Number of Lines To Write String.
2+
// Memory Usage: 8.4 MB, less than 100.00% of C++ online submissions for Number of Lines To Write String.
3+
4+
class Solution
5+
{
6+
public:
7+
vector<int> numberOfLines(vector<int>& widths, string S)
8+
{
9+
int res = 1;
10+
11+
int cur = 0;
12+
for (int index = 0; index < S.length(); )
13+
{
14+
if (cur + widths[S[index] - 'a'] > 100)
15+
{
16+
++res;
17+
cur = 0;
18+
}
19+
else
20+
{
21+
cur += widths[S[index] - 'a'];
22+
++index;
23+
}
24+
}
25+
26+
vector<int> vec = {res, cur};
27+
return vec;
28+
}
29+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.