File tree 3 files changed +57
-1
lines changed
3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 98
98
- [ 1569. Number of Ways to Reorder Array to Get Same BST] ( ./1569/ )
99
99
- [ 1572. Matrix Diagonal Sum] ( ./1572/ )
100
100
- [ 1672. Richest Customer Wealth] ( ./1672/ )
101
+ - [ 1768. Merge Strings Alternately] ( ./1768/ )
101
102
- [ 1791. Find Center of Star Graph] ( ./1791/ )
102
103
- [ 1909. Remove One Element to Make the Array Strictly Increasing] ( ./1909/ )
103
104
- [ 1971. Find if Path Exists in Graph] ( ./1971/ )
@@ -151,7 +152,7 @@ Batch create:
151
152
NOTE: JS IS HERE
152
153
-->
153
154
``` 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"
155
156
```
156
157
> then you can use ` x ` for quick debug.
157
158
You can’t perform that action at this time.
0 commit comments