-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRotateString.java
More file actions
37 lines (28 loc) · 853 Bytes
/
Copy pathRotateString.java
File metadata and controls
37 lines (28 loc) · 853 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
37
class Solution {
public boolean rotateString(String s, String goal) {
if (s.length() != goal.length()){
return false;
}
if (s.equals(goal)){
return true;
}
return (s + s).contains(goal);
}
public boolean rotateStringBrute(String s, String goal) {
if (s.length() != goal.length()){
return false;
}
if (s.equals(goal)){
return true;
}
int n = s.length();
String result = "";
for (int i = 0 ; i < n ; i++) {
result = s.substring(i) + s.substring(0, i);
if (result.equals(goal)){
return true;
}
}
return false;
}
}