在vs2013写的程序,使用sort进行排序,然后对比是否完全一样即可
/*
给定两个字符串,请设计一个方法来判定其中一个字符串是否为另一个字符串的置换。
置换的意思是,通过改变顺序可以使得两个字符串相等。
*/
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include<algorithm>
using namespace std;
class Solution
{
public:
/**
* @param A a string
* @param B a string
* @return a boolean
*/
bool stringPermutation(string& A, string& B)
{
// Write your code here
if (A.size() != B.size())
{
return false;
}
else
{
sort(A.begin(), A.end());
sort(B.begin(), B.end());
if (A == B)
{
return true;
}
else
{
return false;
}
}
}
};
int main()
{
Solution a;
string src = "abbcdefg";
string des = "gfedcbba";
cout << a.stringPermutation(src, des) << endl;
system("pause");
return 0;
}