forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (34 loc) · 855 Bytes
/
main.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
/// Source : https://leetcode.com/problems/rotate-string/description/
/// Author : liuyubobobo
/// Time : 2018-03-10
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/// Brute Force
/// Time Complexity: O(N^2)
/// Space Complexity: O(N)
class Solution {
public:
bool rotateString(string A, string B) {
string cur = A;
for(int i = 0 ; i < A.size() ; i ++){
if(cur == B)
return true;
cur = cur.substr(1) + cur[0];
}
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;
}