why my test output is different from submit output with test case [0,0,4] ?

my idea is put vaild number into it's position

'''

int firstMissingPositive(vector<int>& nums) {

//put num into it's position

// if out of index, do not move it

int n = nums.size();

if(!n) return 1;

```
for(int i =0;i<n;i++){
int t = nums[i];
int j=i + 1;
int id = t-1;
while(t>0 && t<=4 &&nums[id] != t ){
swap(nums[i],nums[id]);
t = nums[i];
id = t-1;
}
}
for(int i = 0;i<n;i++){
if(nums[i] != (i+1)) return (i+1);
}
return n + 1;
}
```

'''

test output is 1, submit output is 2;