Skip to content

Commit fb0aed3

Browse files
add 1768
1 parent 9b2d37f commit fb0aed3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1768|[Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1768.java) ||Easy|String|
1112
|1765|[Map of Highest Peak](https://leetcode.com/problems/map-of-highest-peak/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1765.java) ||Medium|BFS, Graph|
1213
|1764|[Form Array by Concatenating Subarrays of Another Array](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1764.java) ||Medium|Array, Greedy|
1314
|1763|[Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1763.java) ||Easy|String|
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1768 {
4+
public static class Solution1 {
5+
public String mergeAlternately(String word1, String word2) {
6+
StringBuilder sb = new StringBuilder();
7+
int i = 0, j = 0;
8+
for (; i < word1.length() && j < word2.length(); ) {
9+
sb.append(word1.charAt(i++));
10+
sb.append(word2.charAt(j++));
11+
}
12+
while (i < word1.length()) {
13+
sb.append(word1.charAt(i++));
14+
}
15+
while (j < word2.length()) {
16+
sb.append(word2.charAt(j++));
17+
}
18+
return sb.toString();
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)