-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSolution.kt
45 lines (41 loc) · 1.18 KB
/
Solution.kt
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
37
38
39
40
41
42
43
44
45
/**
* Created by Inno Fang on 2018/3/27.
*/
/**
* 44 / 44 test cases passed.
* Status: Accepted
* Runtime: 244 ms
*/
class Solution {
fun rotateString(A: String, B: String): Boolean {
return A.length == B.length && (A + A).contains(B)
}
}
/**
* 39 / 39 test cases passed.
* Status: Accepted
* Runtime: 224 ms
*/
class Solution2 {
fun rotateString(A: String, B: String): Boolean {
if (A.length != B.length) return false
if (A.isEmpty()) return false
val store = mutableListOf<Int>()
A.forEachIndexed { idx, c ->
if (c == B[0])
store.add(idx)
}
if (store.isEmpty()) return false
store.forEach { idx ->
if ((A.substring(idx) + A.substring(0, idx)) == B) return true
}
return false
}
}
fun main(args: Array<String>) {
Solution().rotateString("abcde", "cdeab").let(::println)
Solution().rotateString("abcde", "abced").let(::println)
Solution().rotateString("vcuszhlbtpmksjleuchmjffufrwpiddgyynfujnqblngzoogzg",
"fufrwpiddgyynfujnqblngzoogzgvcuszhlbtpmksjleuchmjf").let(::println)
Solution().rotateString("aa", "a").let(::println)
}