LeetCode 41. First Missing Positive

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void setNum(int* nums,int numsSize,int val){
    if(val<=0||val>numsSize){
        return;
    }
    else if(nums[val-1]==val){
        return;
    }
    else{
        int t=nums[val-1];
        nums[val-1]=val;
        setNum(nums,numsSize,t);
    }
}
int firstMissingPositive(int* nums, int numsSize){
    for(int i=0;i<numsSize;++i){
        int t=nums[i];
        nums[i]=-1;
        setNum(nums,numsSize,t);
    }
    for(int i=0;i<numsSize;++i){
        if(nums[i]<=0){
            return i+1;
        }
    }
    return numsSize+1;
}



17 Replies to “LeetCode 41. First Missing Positive”

  1. Appreciating the time and effort you put into your website and detailed information you present. It’s good to come across a blog every once in a while that isn’t the same old rehashed information. Wonderful read! I’ve saved your site and I’m adding your RSS feeds to my Google account.|

  2. With havin so much content do you ever run into any issues of plagorism or copyright infringement? My site has a lot of completely unique content I’ve either written myself or outsourced but it looks like a lot of it is popping it up all over the web without my authorization. Do you know any ways to help stop content from being ripped off? I’d really appreciate it.|

  3. Right here is the perfect website for anyone who wants to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I personally would want to…HaHa). You certainly put a fresh spin on a subject which has been written about for many years. Great stuff, just wonderful!|

  4. I absolutely love your blog and find nearly all of your post’s to be just what I’m looking for. Do you offer guest writers to write content for you personally? I wouldn’t mind composing a post or elaborating on many of the subjects you write regarding here. Again, awesome weblog!|

  5. Hi there! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My web site looks weird when viewing from my iphone. I’m trying to find a template or plugin that might be able to correct this issue. If you have any recommendations, please share. Appreciate it!|

  6. Pretty nice post. I just stumbled upon your weblog and wished to say that I have truly enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon!|

  7. Hey, I think your site might be having browser compatibility issues. When I look at your blog in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!|

Leave a Reply

Your email address will not be published. Required fields are marked *