File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 337
337
1672|[ Richest Customer Wealth] ( ./1672-richest-customer-wealth.js ) |Easy|
338
338
1716|[ Calculate Money in Leetcode Bank] ( ./1716-calculate-money-in-leetcode-bank.js ) |Easy|
339
339
1748|[ Sum of Unique Elements] ( ./1748-sum-of-unique-elements.js ) |Easy|
340
+ 1768|[ Merge Strings Alternately] ( ./1768-merge-strings-alternately.js ) |Easy|
340
341
1780|[ Check if Number is a Sum of Powers of Three] ( ./1780-check-if-number-is-a-sum-of-powers-of-three.js ) |Medium|
341
342
1791|[ Find Center of Star Graph] ( ./1791-find-center-of-star-graph.js ) |Easy|
342
343
1812|[ Determine Color of a Chessboard Square] ( ./1812-determine-color-of-a-chessboard-square.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1768. Merge Strings Alternately
3
+ * https://leetcode.com/problems/merge-strings-alternately/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given two strings word1 and word2. Merge the strings by adding letters in alternating
7
+ * order, starting with word1. If a string is longer than the other, append the additional
8
+ * letters onto the end of the merged string.
9
+ *
10
+ * Return the merged string.
11
+ */
12
+
13
+ /**
14
+ * @param {string } word1
15
+ * @param {string } word2
16
+ * @return {string }
17
+ */
18
+ var mergeAlternately = function ( word1 , word2 ) {
19
+ let result = '' ;
20
+ for ( let i = 0 ; i < Math . max ( word1 . length , word2 . length ) ; i ++ ) {
21
+ if ( i < word1 . length ) result += word1 [ i ] ;
22
+ if ( i < word2 . length ) result += word2 [ i ] ;
23
+ }
24
+ return result ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments