Why don't you use STL? My solution is below:


  • -1
    Y
    class Solution
    {
    public:
    	int firstMissingPositive(int A[], int n) {
    		if (n == 0)
    			return 1;
    		sort(A, A + n);
    		for (int i = 1; ;i++) {
    			int *p = find(A, A + n, i);
    			if (p == A + n)
    				return i;
    		}		
    	}
    };

  • 4
    C

    The time complexity will be higher than O(n), though this code might be accepted by the OJ.


Log in to reply
 

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