Here is my Code:

```
public int firstMissingPositive(int[] A) {
// Start typing your Java solution below
// DO NOT write main() function
for(int i=0; i < A.length; i++){
while(A[i]>0 && A[i] <= A.length && A[i]!=i+1 && A[i]!=A[A[i]-1] ){
int temp=A[A[i]-1];
A[A[i]-1] = A[i];
A[i]=temp;
}
}
int index=0;
while(index < A.length && A[index]==index+1) index++;
return index+1;
```

}

```
When I change the swapping conditions as below :
int temp=A[i];
A[i]=A[A[i]-1];
A[A[i]-1]=temp;
```

My code throws a Time exceeded error . Any Idea why it is ?

Thanks.