문제풀이 2021 02 21
2021.02.21 연습
- 사용언어 : java
class Solution {
public String mergeAlternately(String word1, String word2) {
StringBuilder sb = new StringBuilder();
char[] arr1 = word1.toCharArray();
char[] arr2 = word2.toCharArray();
int length = Math.max(arr1.length, arr2.length);
for (int i = 0; i < length; i++) {
if (i < arr1.length) {
sb.append(arr1[i]);
}
if (i < arr2.length) {
sb.append(arr2[i]);
}
}
return sb.toString();
}
}
Runtime: 0 ms, faster than 100.00% of Java online submissions for Merge Strings Alternately. Memory Usage: 37.4 MB, less than 40.00% of Java online submissions for Merge Strings Alternately.