(word1 string, word2 string)
| 1 | package merge_strings_alternately_1768 |
| 2 | |
| 3 | func mergeAlternately(word1 string, word2 string) string { |
| 4 | var ( |
| 5 | res string |
| 6 | i, j, k int |
| 7 | ) |
| 8 | |
| 9 | for i+j < len(word1)+len(word2) { |
| 10 | if i < len(word1) && k%2 == 0 { |
| 11 | res += string(word1[i]) |
| 12 | i++ |
| 13 | if j < len(word2) { |
| 14 | k++ |
| 15 | } |
| 16 | } |
| 17 | if j < len(word2) && k%2 == 1 { |
| 18 | res += string(word2[j]) |
| 19 | j++ |
| 20 | if i < len(word1) { |
| 21 | k++ |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | return res |
| 27 | } |
no outgoing calls