# 796.Rotate String

**796.Rotate String**

难度:Easy

> 给定两个字符串, A 和 B。

A 的旋转操作就是将 A 最左边的字符移动到最右边。 例如, 若 A = 'abcde'，在移动一次之后结果就是'bcdea' 。如果在若干次旋转操作之后，A 能变成B，那么返回True。

```
示例 1:
输入: A = 'abcde', B = 'cdeab'
输出: true

示例 2:
输入: A = 'abcde', B = 'abced'
输出: false
注意：

A 和 B 长度不超过 100。
```

最直观的方法，把A旋转后的所有字符串存到集合中，然后判断是否有B。 另一个方法构造2A，如果可以通过旋转得到，则B必然在2A的字符串中。\
就写第一种方法了:

```
class Solution {
public:
    bool rotateString(string A, string B) {

        if(A.length()!=B.length()) return false;
        unordered_set<string> clusterA;
        clusterA.insert(A);
        int len=A.length();
        for(int k=1;k<len;k++)
        {
            string tmp;
            for(int i=k;i<len;i++ )
                tmp+=A[i];
            for(int i=0;i<k;i++)
                tmp+=A[i];
            clusterA.insert(tmp);
            //cout<<tmp<<endl;
        }
        return clusterA.count(B);
        
    }
};
```

> 执行用时 :12ms, 在所有 C++ 提交中击败了7.97%的用户\
> 内存消耗 :10.1MB, 在所有 C++ 提交中击败了5.62%的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/796.rotate_string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
