> For the complete documentation index, see [llms.txt](https://r24zeng.gitbook.io/leetcode-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r24zeng.gitbook.io/leetcode-notebook/wan-quan-an-zhao-jiu-zhang-suan-fa-shua-de-60-dao-zuo-you/ii.-sorted-array/796.-rotate-string.md).

# 796. Rotate String

\# Easy

### Solution:

1. A is original, B is new.&#x20;
2. Find all possible start letter position of B corresponded to A.
3. Then continue comparing following letters bettween A and B.
4. Consider two edge cases: two strings are empty; two strings contain same letter but different lenght.h

```java
// Java
class Solution {
    public boolean rotateString(String s, String goal) {
        // special case
        if(s.length() != goal.length())
            return false;
        
        // regular case
        int l = s.length();
        for(int i = 0; i < l; i ++) {
            if(s.charAt(i) == goal.charAt(0)) {
                int j = l - i;
                if(s.substring(i).equals(goal.substring(0, j)) 
                  && s.substring(0, i).equals(goal.substring(j)))
                    return true;
            }
        }
        
        return false;
    }
}
```
