leetcode每日一题 P3289 数字小镇中的捣蛋鬼
时间轴
2025-10-31
init
题目:
用哈希表空间换时间1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using std::vector;
using std::unordered_map;
class Solution {
    public:
	vector<int> getSneakyNumbers(vector<int> &nums)
	{
		unordered_map<int, int> umap;
		vector<int> res;
		int i, n = nums.size();
		for (i = 0; i < n; i++) {
			umap[nums[i]]++;
			if (umap[nums[i]] == 2) {
				res.push_back(nums[i]);
			}
			if (res.size() == 2) {
				break;
			}
		}
		return res;
	}
};
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 常想一二,不思八九!
 评论




