C++ use flags


  • 0
    I
    class Solution {
    public:
        vector<int> findDisappearedNumbers(vector<int>& nums) {
            bool *flags = new bool[nums.size()];
            memset(flags, 0, nums.size());
            vector<int> result;
            for(vector<int>::iterator it = nums.begin(); it != nums.end(); ++it){
                *(flags+(*it-1))=true;
            }
            
            for(int i = 0; i < nums.size(); ++i){
                if(!(*(flags+i))) result.push_back(i+1);
            }
            delete flags;
            
            return result;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.