We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4fff2fe commit 790a112Copy full SHA for 790a112
22 July Smallest Positive Missing
@@ -0,0 +1,22 @@
1
+class Solution {
2
+ public:
3
+ int missingNumber(vector<int> &nums) {
4
+ // code here
5
+ int n=nums.size();
6
+
7
+ for (int i = 0; i < n; i++) {
8
+ while (nums[i] > 0 && nums[i] <= n && nums[nums[i] - 1] != nums[i]) {
9
+ swap(nums[i], nums[nums[i] - 1]);
10
+ }
11
12
13
+ // Second pass: find the first index where nums[i] != i + 1
14
15
+ if (nums[i] != i + 1)
16
+ return i + 1;
17
18
19
+ return n + 1;
20
21
+};
22
0 commit comments