Skip to content

Commit c15a547

Browse files
committed
✨ [1768] a1
1 parent 80d3680 commit c15a547

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

1768/my_solution.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @param {string} word1
3+
* @param {string} word2
4+
* @return {string}
5+
*/
6+
var mergeAlternately = function (word1, word2) {
7+
let str = "";
8+
word1 = word1.split(""), word2 = word2.split("");
9+
while (word1.length > 0 || word2.length > 0) {
10+
let curr1 = "", curr2 = "";
11+
console.log(word1)
12+
console.log(word2)
13+
if (word1.length > 0) {
14+
curr1 = word1.shift();
15+
}
16+
17+
if (word2.length > 0) {
18+
curr2 = word2.shift();
19+
}
20+
21+
str += curr1 + curr2;
22+
}
23+
24+
return str;
25+
};
26+
let x =
27+
mergeAlternately("abc", "pqr")
28+
29+
console.log("Res")
30+
console.log(x)

1768/solution.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {string} word1
3+
* @param {string} word2
4+
* @return {string}
5+
*/
6+
var mergeAlternately = function (word1, word2) {
7+
let str = "";
8+
word1 = word1.split(""), word2 = word2.split("");
9+
while (word1.length > 0 || word2.length > 0) {
10+
let curr1 = "", curr2 = "";
11+
console.log(word1)
12+
console.log(word2)
13+
if (word1.length > 0) {
14+
curr1 = word1.shift();
15+
}
16+
17+
if (word2.length > 0) {
18+
curr2 = word2.shift();
19+
}
20+
21+
str += curr1 + curr2;
22+
}
23+
24+
return str;
25+
};

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
- [1569. Number of Ways to Reorder Array to Get Same BST](./1569/)
9999
- [1572. Matrix Diagonal Sum](./1572/)
100100
- [1672. Richest Customer Wealth](./1672/)
101+
- [1768. Merge Strings Alternately](./1768/)
101102
- [1791. Find Center of Star Graph](./1791/)
102103
- [1909. Remove One Element to Make the Array Strictly Increasing](./1909/)
103104
- [1971. Find if Path Exists in Graph](./1971/)
@@ -151,7 +152,7 @@ Batch create:
151152
NOTE: JS IS HERE
152153
-->
153154
```ssh
154-
chapter=212 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
155+
chapter=1768 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
155156
```
156157
> then you can use `x` for quick debug.
157158

0 commit comments

Comments
 (0)