题目链接:859. 亲密字符串 - 力扣(LeetCode) (leetcode-cn.com)
难度:Easy
考虑以下几种情况:
- 两字符串完全相等
- 无重复字符,返回
- 有重复字符,返回
- 两字符串不相等
- 两字符串中出现过的字符不一致,返回
- 两字符串不相等的字符个数 ,返回
- 两字符串不相等的两对字符交换后相等,返回
class Solution {
private:
vector<int> _nums;
public:
Solution(vector<int>& nums) {
this->_nums = nums;
}
vector<int> reset() {
return this->_nums;
}
vector<int> shuffle() {
vector<int> ans = this->_nums;
int len = this->_nums.size();
for(int i=0;i<len;i++){
int ind = rand()%len;
int t = ans[ind];
ans[ind] = ans[i];
ans[i] = t;
}
return ans;
}
};