Q137.h 489 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // Created by 李洋 on 2023/10/16.
  3. //
  4. #ifndef LEECODE_C_Q137_H
  5. #define LEECODE_C_Q137_H
  6. #include <vector>
  7. #include <map>
  8. using namespace std;
  9. class Q137 {
  10. public:
  11. int singleNumber(vector<int> &nums) {
  12. unordered_map<int, int> m;
  13. for (int i: nums) {
  14. m[i] = m[i] + 1;
  15. }
  16. for (auto [num, count]: m) {
  17. if (count == 1) {
  18. return num;
  19. }
  20. }
  21. return -1;
  22. }
  23. };
  24. #endif //LEECODE_C_Q137_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。