LeetCode每日一题:859. 亲密字符串【2021/11/23】

125 阅读1分钟

题目链接:859. 亲密字符串 - 力扣(LeetCode) (leetcode-cn.com)

难度:Easy

考虑以下几种情况:

  1. 两字符串完全相等
    1. 无重复字符,返回 falsefalse
    2. 有重复字符,返回 truetrue
  2. 两字符串不相等
    1. 两字符串中出现过的字符不一致,返回 falsefalse
    2. 两字符串不相等的字符个数 >2>2,返回 falsefalse
    3. 两字符串不相等的两对字符交换后相等,返回 truetrue
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;
    }
};