Skip to content

Commit

Permalink
set, map
Browse files Browse the repository at this point in the history
  • Loading branch information
czqmike committed Feb 23, 2020
1 parent 2f914d7 commit 0b87e9a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode
.vscode
*.exe
test.cpp
44 changes: 44 additions & 0 deletions 面试题56 - II. 数组中数字出现的次数 II.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
在一个数组 nums 中除一个数字只出现一次之外,其他数字都出现了三次。请找出那个只出现一次的数字。
 
示例 1:
输入:nums = [3,4,3,3]
输出:4
示例 2:
输入:nums = [9,1,7,9,7,9,7]
输出:1
 
限制:
1 <= nums.length <= 10000
1 <= nums[i] < 2^31
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
*/

class Solution {
public:
int singleNumber(vector<int>& nums) {
multiset<int> s;
for (auto it = nums.begin(); it != nums.end(); ++it) {
s.insert(*it);
}

int ret = 0;
for (auto it = s.begin(); it != s.end(); ++it) {
if (s.count(*it) == 1) {
ret = *it;
break;
}
}

return ret;
}
};

0 comments on commit 0b87e9a

Please sign in to comment.