250x250
Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- JPA
- 스택
- sql
- dfs
- priority_queue
- deque
- map
- math
- date
- NIO
- 리소스모니터링
- CSS
- spring boot
- 큐
- Properties
- GC로그수집
- alter
- BFS
- Calendar
- html
- 스프링부트
- string
- scanner
- set
- javascript
- Union-find
- List
- union_find
- Java
- 힙덤프
Archives
- Today
- Total
매일 조금씩
Leet code (Easy): 1768. Merge Strings Alternately - Java 본문
728x90
반응형
class Solution {
public String mergeAlternately(String word1, String word2) {
StringBuilder merged = new StringBuilder();
int maxLength = Math.max(word1.length(), word2.length());
for(int i = 0; i < maxLength; i++){
if(i < word1.length()){
merged.append(word1.charAt(i));
}
if(i < word2.length()){
merged.append(word2.charAt(i));
}
}
return merged.toString();
}
}
728x90
반응형
'알고리즘 > String' 카테고리의 다른 글
Leet code (Medium): 647. Palindromic Substrings (중심확장법) - Java (0) | 2024.10.28 |
---|---|
Leet code (Medium): 5. Longest Palindromic Substring (중심확장법)- Java (0) | 2024.10.28 |
Leet code (Easy): 125. Valid Palindrome (투 포인터) - Java (0) | 2024.10.28 |
Leet code (Easy): 20. Valid Parentheses (Stack) - Java (0) | 2024.10.27 |
Leet code (Medium): 49. Group Anagrams - Java (0) | 2024.10.27 |