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
- Counting
- Math
- greedy
- dynamic programming
- 자바
- Tree
- 구현
- Binary Search
- SQL
- Method
- database
- 파이썬
- 코테
- java
- hash table
- Data Structure
- sorting
- Number Theory
- 코딩테스트
- Matrix
- two pointers
- bit manipulation
- implement
- string
- geometry
- array
- Stack
- Binary Tree
- simulation
- Class
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1768. Merge Strings Alternately 본문
1. Input
1) 문자열 word1
2) 문자열 word2
2. Output
1) word1부터 번갈아가면서 1글자씩 합친 결과 문자열
2) 한쪽이 더 길다면 남은 문자열을 맨 뒤에 붙여서 반환
3. Constraint
1) 1 <= word1.length, word2.length <= 100
2) word1과 word2는 영어 소문자로 이루어져 있다.
4. Example
Input: word1 = "abc", word2 = "pqr" -> Output: "apbqcr“
Input: word1 = "ab", word2 = "pqrs" -> Output: "apbqrs"
5. Code
1) 첫 코드(2022/06/15)
int l1 = word1.length();
int l2 = word2.length();
String result = "";
if(l1 > l2){
for(int i=0 ; i<l2 ; i++){
result += word1.charAt(i) + "";
result += word2.charAt(i) + "";
}
result += word1.substring(l2,l1);
} else if(l1 < l2){
for(int i=0 ; i<l1 ; i++){
result += word1.charAt(i) + "";
result += word2.charAt(i) + "";
}
result += word2.substring(l1,l2);
} else{
for(int i=0 ; i<l1 ; i++){
result += word1.charAt(i) + "";
result += word2.charAt(i) + "";
}
}
return result;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1791. Find Center of Star Graph (0) | 2023.01.04 |
---|---|
[LeetCode/Easy] 1773. Count Items Matching a Rule (0) | 2023.01.04 |
[LeetCode/Medium] 16. 3Sum Closest (0) | 2023.01.03 |
[LeetCode/Easy] 1742. Maximum Number of Balls in a Box (0) | 2023.01.03 |
[LeetCode/Easy] 1732. Find the Highest Altitude (0) | 2023.01.02 |