My JavaScript Solution Understandable Variable Naming


  • 0
    I
    var firstMissingPositive = function(nums) {
        var numsLen = nums.length, index, sortedNums = [0], sortedNumsLen;
        if (!nums) return 1;
        for (index = 0; index < numsLen; index++) {
            if (nums[index] > 0 && nums[index] <= numsLen) {
                sortedNums[nums[index]] = nums[index];
            }
        }
        for (index = 0, sortedNumsLen = sortedNums.length; index < sortedNumsLen; index++) {
            if (sortedNums[index] !== index) {
                break;
            }
        }
        return index;
    };

Log in to reply
 

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