码迷,mamicode.com
首页 > 其他好文 > 详细

两个字符串是变位词

时间:2015-09-05 23:43:27      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

class Solution {
public:
    /**
     * @param s: The first string
     * @param b: The second string
     * @return true or false
     */
    bool anagram(string s, string t) {
        // write your code here
        vector<char> vec1,vec2;
        for(int i = 0; i < s.size(); ++i)
            vec1.push_back(s[i]);
        for(int j =0; j < t.size(); ++j)
            vec2.push_back(t[j]);
        sort(vec1.begin(),vec1.end());
        sort(vec2.begin(),vec2.end());
        return vec1 == vec2;
    }
};

 

两个字符串是变位词

标签:

原文地址:http://www.cnblogs.com/smallby/p/4784197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!