标签:ret size div 位置 == vector public code amp
题目:
解答:
方法一:
方法二:
方法三
:
1 class Solution { 2 public: 3 int firstMissingPositive(vector<int>& nums) 4 { 5 for (int i = 0; i < nums.size(); i++) 6 { 7 while (nums[i] != i + 1) 8 { 9 if (nums[i] <= 0 || nums[i] > nums.size() || nums[i] == nums[nums[i] - 1]) 10 { 11 break; 12 } 13 14 // 将nums[i] 放置到对应位置上[1,2,3...] 15 int idx = nums[i] - 1; 16 nums[i] = nums[idx]; 17 nums[idx] = idx + 1; 18 } 19 } 20 for (int i = 0; i < nums.size(); i++) 21 { 22 if (nums[i] != (i + 1)) 23 { 24 return (i + 1); 25 } 26 } 27 return (nums.size() + 1); 28 } 29 };
标签:ret size div 位置 == vector public code amp
原文地址:https://www.cnblogs.com/ocpc/p/12830793.html