Leetcode Note: Go - Merge Strings Alternately

Merge Strings Alternately - LeetCode
https://leetcode.com/problems/merge-strings-alternately/

  • Go 言語で取り組んだメモ

回答

Golang Simple Solution - Merge Strings Alternately - LeetCode
https://leetcode.com/problems/merge-strings-alternately/solutions/2666394/golang-simple-solution/

func mergeAlternately(word1 string, word2 string) string {
    var res []byte
    for i:= 0; i < len(word1) || i < len(word2); i++ {
        if i < len(word1) {
            res = append(res, word1[i])
        }
        
        if i < len(word2) {
            res = append(res, word2[i])
        }
    }
    
    return string(res)
}