https://leetcode.com/problems/merge-strings-alternately/?envType=study-plan-v2&envId=leetcode-75

class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
result = []
min_len = min(len(word1),len(word2))
for i, j in zip(word1, word2):
result.append(i)
result.append(j)
result.extend([word1[min_len:], word2[min_len:]])
return ''.join(result)
# .append(x)는 리스트 끝에 x 1개를 그대로 넣음.
# .extend(iterable)는 리스트 끝에 가장 바깥쪽 iterable의 모든 항목을 넣음.
class Solution {
public String mergeAlternately(String word1, String word2) {
StringBuilder result = new StringBuilder(word1.length() + word2.length());
int min_len = Math.min(word1.length(), word2.length());
for (int i = 0; i < min_len; i++){
result.append(word1.charAt(i)).append(word2.charAt(i));
}
result.append(word1.substring(min_len)).append(word2.substring(min_len));
return result.toString();
}
}
// substring 함수
// String substring(int index)
// index의 위치를 포함하여 이후 모든 문자열 리턴
// String substring(int begin, int end)
// begin 시작하여 end 전까지 모든 문자열 리턴