//给你一个未排序的整数数组,请你找出其中没有出现的最小的正整数。 // // // // 示例 1: // // 输入: [1,2,0] //输出: 3 // // // 示例 2: // // 输入: [3,4,-1,1] //输出: 2 // // // 示例 3: // // 输入: [7,8,9,11,12] //输出: 1 // // // // // 提示: // // 你的算法的时间复杂度应为O(n),并且只能使用常数级别的额外空间。 // Related Topics 数组 // 👍 907 👎 0 //leetcode submit region begin(Prohibit modification and deletion) class Solution { public int firstMissingPositive(int[] nums) { int result = 1; for (int num : nums) { if (num == result){ result++; } } return result; } } //leetcode submit region end(Prohibit modification and deletion)
2020-01-05 缺失的第一个正整数
最新推荐文章于 2022-01-15 19:43:18 发布