We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 51e2e24 commit a640c45Copy full SHA for a640c45
1 file changed
Strings/MergeStringsAlternatively.java
@@ -0,0 +1,33 @@
1
+class MergeStringsAlternatively {
2
+ public String mergeAlternately(String word1, String word2) {
3
+ int s1 = word1.length();
4
+ int s2 = word2.length();
5
+
6
+ StringBuilder sb = new StringBuilder();
7
8
+ if(s1<s2){
9
+ for(int i = 0; i<s1; i++){
10
+ sb.append(word1.charAt(i));
11
+ sb.append(word2.charAt(i));
12
+ }
13
14
+ sb.append(word2.substring(s1, s2));
15
16
+ else if(s2<s1){
17
+ for(int i = 0; i<s2; i++){
18
19
20
21
22
+ sb.append(word1.substring(s2, s1));
23
24
+ else{
25
26
27
28
29
30
31
+ return sb.toString();
32
33
+}
0 commit comments