-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.vscode | ||
.vscode | ||
*.exe | ||
test.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |