lintcode-189

class Solution {
public:
    /**    
     * @param A: a vector of integers
     * @return: an integer
     */
    int findMaxArr(vector vec)
    {
        int max=vec[0],size=vec.size();
        for(int i=1;imax)
                max=vec[i];
        }
        return max;
    }
    int firstMissingPositive(vector A) {
        // write your code here
        if(A.empty())
            return 1;
        if(A.size()==1&&A[0]>0){
            return A[0]==1?2:1;
        }
        const int maxsize=findMaxArr(A)+1;
        if(maxsize<=1)
            return 1;
        int count[maxsize];
        memset(count,0,sizeof(count));
        for(auto e:A){
            if(e>0)
                ++count[e];
        }
        for(int i=1;i

你可能感兴趣的:(Lintcode)