Share my c++ solution


  • 0
    Y
    class Solution {
    public:
        int missingNumber(vector<int>& nums) {
            int size = nums.size();
            int isExe[size + 1] = {0};
            for(int i = 0; i < size; i++) {
                isExe[nums[i]] = 1;
            }
            for(int i = 0; i < size + 1; i++) {
                if(isExe[i] == 0) return i;
            }
        }
    };

  • 0
    D

    it is mentioned that the ideal solution has to has a constant space complexity your solution has linear space complexity.


Log in to reply
 

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