forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.cpp
52 lines (40 loc) · 1.02 KB
/
main2.cpp
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
46
47
48
49
50
51
52
/// Source : https://leetcode.com/problems/rotate-string/description/
/// Author : liuyubobobo
/// Time : 2018-03-11
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/// Brute Force
/// No more actual space:)
///
/// Time Complexity: O(N^2)
/// Space Complexity: O(1)
class Solution {
public:
bool rotateString(string A, string B) {
if(A.size() != B.size())
return false;
for(int offset = 0; offset < A.size(); offset ++){
int i = 0;
for(i = 0 ; i < B.size() ; i ++)
if(B[i] != A[(i + offset)%A.size()])
break;
if(i == B.size())
return true;
}
return false;
}
};
void print_bool(bool res){
cout << (res ? "True" : "False") << endl;
}
int main() {
string A1 = "abcde";
string B1 = "cdeab";
print_bool(Solution().rotateString(A1, B1));
string A2 = "abcde";
string B2 = "abced";
print_bool(Solution().rotateString(A2, B2));
return 0;
}