해당 문제는 다음 leetcode의 문제입니다:
https://leetcode.com/problems/single-number/
Single Number - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com

#define MAXSIZE 30000
class Solution {
public:
int singleNumber(vector<int>& nums) {
int positive[MAXSIZE] = {0, }, negative[MAXSIZE]={0, } ;
for(vector<int>::iterator iter = nums.begin() ; iter != nums.end() ; iter++){
if(0 <= *iter)
positive[*iter] += 1 ;
else
negative[-(*iter)] += 1;
}
int answer = MAXSIZE ;
for(int i = 0 ; i < MAXSIZE && answer == MAXSIZE ; i++){
if(positive[i] == 1)
answer = i ;
else if(negative[i] == 1)
answer = -i ;
}
return answer ;
}
};
저는 위와 같이 풀었습니다.

위와 같이 문제 해결했습니다. 속도는 그리 빠르지 않기에 추가적으로 다른 분들은 코드와 비교해봐야겠습니다.
제 코드는 Github를 통해서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/LeetCode/P136_Single_Number.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
https://sabarada.tistory.com/160
[LeetCode] Single Number 개인풀이
문제 integer 배열이 주어집니다. 1개의 숫자를 제외하고는 2번씩 노출됩니다. 1번만 노출되는 숫자를 찾으세요. 나아가기 : O(N) 시간복잡도와 O(1)의 공간복잡도를 가질 수 있도록 해결할 수 있으면
sabarada.tistory.com
해당 블로그의 풀이를 보니 바로 이해할 수 있었습니다.
훈수 및 조언은 언제든지 환영입니다.
해당 문제는 다음 leetcode의 문제입니다:
https://leetcode.com/problems/single-number/
Single Number - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com

#define MAXSIZE 30000
class Solution {
public:
int singleNumber(vector<int>& nums) {
int positive[MAXSIZE] = {0, }, negative[MAXSIZE]={0, } ;
for(vector<int>::iterator iter = nums.begin() ; iter != nums.end() ; iter++){
if(0 <= *iter)
positive[*iter] += 1 ;
else
negative[-(*iter)] += 1;
}
int answer = MAXSIZE ;
for(int i = 0 ; i < MAXSIZE && answer == MAXSIZE ; i++){
if(positive[i] == 1)
answer = i ;
else if(negative[i] == 1)
answer = -i ;
}
return answer ;
}
};
저는 위와 같이 풀었습니다.

위와 같이 문제 해결했습니다. 속도는 그리 빠르지 않기에 추가적으로 다른 분들은 코드와 비교해봐야겠습니다.
제 코드는 Github를 통해서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/LeetCode/P136_Single_Number.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
https://sabarada.tistory.com/160
[LeetCode] Single Number 개인풀이
문제 integer 배열이 주어집니다. 1개의 숫자를 제외하고는 2번씩 노출됩니다. 1번만 노출되는 숫자를 찾으세요. 나아가기 : O(N) 시간복잡도와 O(1)의 공간복잡도를 가질 수 있도록 해결할 수 있으면
sabarada.tistory.com
해당 블로그의 풀이를 보니 바로 이해할 수 있었습니다.
훈수 및 조언은 언제든지 환영입니다.