Skip to content

Commit 88e801e

Browse files
committed
feat: java code : Leetcode-1768
1 parent cdaf3df commit 88e801e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Merge Strings Alternately.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public String mergeAlternately(String word1, String word2) {
3+
StringBuilder mergedWord = new StringBuilder();
4+
int i = 0;
5+
int w1=word1.length();
6+
int w2=word2.length();
7+
while(i< w1|| i< w2){
8+
if(i< w1){
9+
mergedWord.append(word1.charAt(i));
10+
}
11+
if(i < w2){
12+
mergedWord.append(word2.charAt(i));
13+
}
14+
i++;
15+
}
16+
return mergedWord.toString();
17+
}
18+
}

0 commit comments

Comments
 (0)