알고리즘 문제풀이/LeetCode

LeetCode 448번 - Find All Numbers Disappeared in an Array

leetcode.com/problems/find-all-numbers-disappeared-in-an-array/

 

Find All Numbers Disappeared in an Array - 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

class Solution {
public:
    vector<int> findDisappearedNumbers(vector<int>& nums) {
    
        vector<int> result;
        set<int> s;
        vector<int> last;
        
        for(int i=0; i<nums.size(); i++){
            s.insert(nums[i]);
        }
        
        int i = 1;
        for(auto it = s.begin(); i <= nums.size(); i++){
		    if(*it != i){
                result.push_back(i);
            }
            else{
                it++;
            }
	    }
        
        return result;
    }
};



//1)우선 셋에 집어넣고 중복 해제후, sorting 된 상태로 만듬
//2)셋의 마지막 value를 통해서 1<<n으로 for문 돌리기
//3)비교하다가 i값이 없으면 그걸 추가..!!