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
- hash table
- greedy
- 파이썬
- Number Theory
- simulation
- Matrix
- Tree
- 구현
- 코테
- database
- 코딩테스트
- two pointers
- SQL
- Stack
- Counting
- array
- Math
- string
- Binary Search
- geometry
- java
- 자바
- Class
- Data Structure
- sorting
- Binary Tree
- bit manipulation
- Method
- implement
- dynamic programming
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 잘라서 배열로 저장하기 본문
1. Input
1) 문자열 my_str
2) 정수 n
2. Output
1) my_str을 길이 n씩 잘라서 저장한 배열
2) 남은 문자열이 n보다 짧으면 그대로 저장
3. Constraint
1) 1 ≤ my_str의 길이 ≤ 100
2) 1 ≤ n ≤ my_str의 길이
3) my_str은 알파벳 소문자, 대문자, 숫자로 이루어져 있다.
4. Example
Input: my_str={abc123def45}, n=3 -> Output: {“abc”,“123”,“def”,“45}
5. Code
1) 첫 코드(2022/10/31)
import java.util.ArrayList;
// main()
ArrayList<String> list = new ArrayList();
while(!my_str.equals("")){
if(my_str.length()>=n){
list.add(my_str.substring(0,n));
my_str = my_str.substring(n,my_str.length());
} // if
else{
list.add(my_str);
break;
} // else
} // while
return list.toArray(new String[] {});
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.0] 머쓱이보다 키 큰 사람 (0) | 2022.11.02 |
---|---|
[프로그래머스/Lv.0] 중복된 숫자 개수 (0) | 2022.11.02 |
[프로그래머스/Lv.0] 7의 개수 (0) | 2022.11.02 |
[프로그래머스/Lv.0] 문자열 정렬하기 (2) (0) | 2022.11.01 |
[프로그래머스/Lv.0] 세균 증식 (0) | 2022.11.01 |