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

Commitfd318bd

Browse files
committed
Update : PR Review comments addressed
1 parentd0f7ba7 commitfd318bd

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
classSolution {
22
publicStringmergeAlternately(Stringword1,Stringword2) {
3-
inti =0,j =0;
3+
inti =0;
44
StringBuilderres =newStringBuilder();
55

6-
while (i <word1.length() &&j <word2.length()) {
7-
res.append(word1.charAt(i));
8-
res.append(word2.charAt(j));
6+
while (i <word1.length() ||i <word2.length()) {
7+
if (i <word1.length()) {
8+
res.append(word1.charAt(i));
9+
}
10+
if (i <word2.length()) {
11+
res.append(word2.charAt(i));
12+
}
913
i++;
10-
j++;
1114
}
1215

13-
res.append(word1.substring(i));
14-
res.append(word2.substring(j));
1516
returnres.toString();
1617
}
17-
}
18+
}
19+
20+
/**
21+
* Time Complexity : O(n+m)
22+
* Space Complexity : O(n+m)
23+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp