本文共 411 字,大约阅读时间需要 1 分钟。
Given an unsorted integer array, find the smallest missing positive integer.
Example 1:
Input: [1,2,0]
Output: 3
Example 2:
Input: [3,4,-1,1]
Output: 2
class Solution { public int firstMissingPositive(int[] nums) { Arrays.sort(nums); int j = 1; for(int i = 0; i < nums.length; i++){ if(nums[i] == j) j++; } return j; }}
看了下别人的方法好像都比我复杂?
转载地址:http://gfqvb.baihongyu.com/