1 solutions
-
0
没过样例啊哈哈哈哈哈哈
#include <bits/stdc++.h> using i64 = int64_t; // <+> class Solution { public: int majorityElement(std::vector<int> &nums) { int candidate = -1; int count = 0; for (int num : nums) { if (num == candidate) ++count; else if (--count < 0) { candidate = num; count = 1; } } return candidate; } }; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int N; std::cin >> N; std::vector<int> l(N); for (auto &i : l) std::cin >> i; std::cout << Solution().majorityElement(l) << '\n'; return 0 ^ 0; }
Information
- ID
- 194
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 9
- Tags
- # Submissions
- 256
- Accepted
- 23
- Uploaded By