-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConsecutiveStrings.java
More file actions
36 lines (28 loc) · 934 Bytes
/
ConsecutiveStrings.java
File metadata and controls
36 lines (28 loc) · 934 Bytes
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
32
33
34
35
36
package com.smlnskgmail.jaman.codewarsjava.kyu6;
// https://www.codewars.com/kata/56a5d994ac971f1ac500003e
public class ConsecutiveStrings {
private final String[] array;
@SuppressWarnings("checkstyle:memberName")
private final int k;
public ConsecutiveStrings(String[] array, int k) {
this.array = array;
this.k = k;
}
public String solution() {
int arrayLength = array.length;
String result = "";
if (arrayLength == 0 || arrayLength < k || k <= 0) {
return result;
}
for (int i = 0; i < arrayLength - k + 1; i++) {
StringBuilder tempData = new StringBuilder();
for (int j = i; j < i + k; j++) {
tempData.append(array[j]);
}
if (result.length() < tempData.length()) {
result = tempData.toString();
}
}
return result;
}
}