本文主要是介绍面试题 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;}
};
这篇关于面试题 01.02. Check Permutation LCCI的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!