https://school.programmers.co.kr/learn/courses/30/lessons/120913
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public String[] solution(String my_str, int n) {
int size = my_str.length()/n;
if(my_str.length() % n != 0){
size++;
}
String[] answer = new String[size];
int index = 0;
for(int i = 0 ; i < my_str.length() ; ){
int next = Math.min(i+n,my_str.length());
answer[index] = my_str.substring(i,next);
i += n;
index++;
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
백준 15558번 점프 게임 (JAVA) (0) | 2023.01.16 |
---|---|
프로그래머스 귤 고르기(JAVA) (0) | 2023.01.15 |
프로그래머스 푸드 파이트 (JAVA) (0) | 2023.01.13 |
프로그래머스 크기가 작은 부분 문자열 (JAVA) (0) | 2023.01.12 |
프로그래머스 N개의 최소공배수 (JAVA) (0) | 2023.01.11 |