๋ฌธ์
์๋ผ์ ๋ฐฐ์ด๋ก ์ ์ฅํ๊ธฐ
ํ์ด
class Solution {
public String[] solution(String my_str, int n) {
int length = my_str.length() % n == 0 ? my_str.length() / n : my_str.length() / n + 1;
String[] answer = new String[length];
for (int i = 0; i < length; i++) {
int start = i * n;
int end = Math.min(start + n, my_str.length());
answer[i] = my_str.substring(start, end);
}
return answer;
}
}
'๐ Coding Test > Programmers Lv0' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค Lv0] ์จ์ด์๋ ์ซ์์ ๋ง์ (2) | ์๋ฐ (0) | 2024.12.18 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค Lv0] ์ง๋ฃ์์ ์ ํ๊ธฐ | ์๋ฐ (0) | 2024.10.31 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv0] n ๋ฒ์งธ ์์๋ถํฐ | ์๋ฐ (0) | 2024.10.24 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv0] ๋ฐฐ์ด ์กฐ๊ฐํ๊ธฐ | ์๋ฐ (0) | 2024.10.24 |