Skip to content

Commit 250914b

Browse files
authored
Create 796_rotate_string.cpp
1 parent 5ae9b78 commit 250914b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

solutions/796_rotate_string.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
bool rotateString(string s, string goal) {
4+
if(s.size()!=goal.size()){
5+
return false;
6+
}
7+
if(s==goal){
8+
return true;
9+
}
10+
int n = s.size()-1;
11+
12+
while(n--){
13+
char ch = s[0];
14+
s.erase(0,1);
15+
s+=ch;
16+
if(s == goal){
17+
return true;
18+
}
19+
}
20+
return false;
21+
}
22+
};

0 commit comments

Comments
 (0)