fix: improvement
This commit is contained in:
parent
290344cc78
commit
e24ac8a0f6
|
|
@ -11,16 +11,14 @@
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
static std::vector<int> findErrorNums(const std::vector<int>& n) {
|
static std::vector<int> findErrorNums(const std::vector<int>& n) {
|
||||||
std::vector<bool> s(n.size() + 1);
|
int x = 0, y = 0, m = n.size();
|
||||||
int x = 0;
|
std::vector<bool> s(m);
|
||||||
for (int i : n) {
|
for (int i = 0; i < m; ++i) {
|
||||||
if (s[i])
|
if (s[n[i] - 1])
|
||||||
x = i;
|
x = n[i];
|
||||||
s[i] = true;
|
s[n[i] - 1] = true;
|
||||||
|
y ^= (i + 1) ^ n[i];
|
||||||
}
|
}
|
||||||
for (int i = 1; i <= s.size(); ++i)
|
return {x, x ^ y};
|
||||||
if (!s[i])
|
|
||||||
return {x, i};
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue