Strings - Rotate String

Strings - Rotate String

Rotate String

https://leetcode.com/problems/rotate-string/description/

Hint:

Use 'substr' method to change the string without actually modifying the string.

Code:

class Solution {
public:
    bool rotateString(string s, string goal) {
        if(s.size()!=goal.size()){
            return false;
        }

        int n = s.size();

        for(int i=0;i<n;i++){
            string temp = s.substr(i+1,n)+s.substr(0,i+1);
            if(temp==goal){
                return true;
            }
        }

        return false;
    }
};