解决方案
对于一个排好序的序列,对相同的数字随机打乱顺序后期望有多少个数字保持原位置不变。

题解
经过分析,我们发现不同能力值的简历是不会互相影响的,所以问题可以简化为有一个长度为n的数组,将里面的元素按照全排列随机排序后,问有多少个元素还在原位。

方法一:
排序 + 除重
C++ 实现
class Solution {
public:
int expectNumber(vector<int>& scores) {
sort(scores.begin(), scores.end());
return unique(scores.begin(), scores.end()) - scores.begin();
}
};
复杂度分析
