面试题 01.02. Check Permutation LCCI

Problem

Given two strings,write a method to decide if one is a permutation of the other.
Note:

0 <= len(s1) <= 100
0 <= len(s2) <= 100

Example1

Input: s1 = “abc”, s2 = “bca”
Output: true

Example2

Input: s1 = “abc”, s2 = “bad”
Output: false

Solution

哈希表或排序

class Solution {
public:
    bool CheckPermutation(string s1, string s2) {
        sort(s1.begin(),s1.end());
        sort(s2.begin(),s2.end());

        return s1 == s2;

    }
};
发布了526 篇原创文章 · 获赞 215 · 访问量 54万+

猜你喜欢

转载自blog.csdn.net/sjt091110317/article/details/105061013