프로그래머스 120921 문자열 밀기

1 개요[ | ]

프로그래머스 120921 문자열 밀기

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

int solution(string A, string B) {
    int len = A.length();
    for(int i=0; i<len; i++) {
        if(A.substr(0, len-i) == B.substr(i) && A.substr(len-i) == B.substr(0, i)) {
            return i;
        }
    }
    return -1;
}
#include <string>
#include <vector>

using namespace std;

int solution(string A, string B)
{
    return (B+B).find(B);
}
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(string A, string B) {
    for(int i=0; i<A.length(); i++) {
        if(A == B) {
            return i;
        }
        rotate(A.begin(), A.end()-1, A.end());
    }
    return -1;
}