CodeWars 마흔 한 번째 문제
Updated:
Consecutive strings
public static String longestConsec(String[] strarr, int k) {
String consec = "";
for(int i = 0 ; i < strarr.length - k + 1; i++) {
String tempConsec = "";
for(int j = i; j < i+k; j++) {
tempConsec += strarr[j];
}
if(consec.length() < tempConsec.length()) {
consec = tempConsec;
}
}
return consec;
}
- 처음부터 K만큼 순서대로 문자열을 더해 이전 더한 문자열과 길이 비교하여 출력하는 문제다.
- best 코드도 나랑 같다.