-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculateStringRotation.java
More file actions
34 lines (28 loc) · 985 Bytes
/
CalculateStringRotation.java
File metadata and controls
34 lines (28 loc) · 985 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
package com.smlnskgmail.jaman.codewarsjava.kyu6;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;
// https://www.codewars.com/kata/5596f6e9529e9ab6fb000014
public class CalculateStringRotation {
private final String start;
private final String end;
public CalculateStringRotation(String start, String end) {
this.start = start;
this.end = end;
}
public int solution() {
List<String> symbols = Arrays.asList(start.split(""));
int length = start.length();
return IntStream
.range(0, length)
.filter(value -> {
List<String> tempSymbols = new ArrayList<>(symbols);
Collections.rotate(tempSymbols, value);
return end.equals(String.join("", tempSymbols));
})
.findFirst()
.orElse(-1);
}
}