Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit22c13b7

Browse files
Add files via upload
1 parent1f77cc1 commit22c13b7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines 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+
classSolution
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)

[8]ページ先頭

©2009-2025 Movatter.jp