---
# System prepended metadata

title: 0796. Rotate String
tags: [Leetcode, Easy, String]

---

# 0796. Rotate String
###### tags: `Leetcode` `Easy` `String`
Link: https://leetcode.com/problems/rotate-string/description/
## Code
### 思路1
```java=
class Solution {
    public boolean rotateString(String s, String goal) {
        return s.length()==goal.length() && (goal+goal).contains(s);
    }
}
```
### 思路2
```java=
class Solution {
    public boolean rotateString(String s, String goal) {
        if(s==null || goal==null) return false;
        if(s.length()!=goal.length()) return false;
        if(s.length()==0) return true;
        for(int i=0; i<goal.length(); i++){
            if(rotateMatch(s, goal, i)) return true;
        }
        return false;
    }
    public boolean rotateMatch(String s, String t, int idx){
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i)!=t.charAt((i+idx)%s.length())) return false; 
        }
        return true;
    }
}
```