First TLE:

```
if not nums:
return 1
for i in xrange(len(nums)):
while 1 <= nums[i] <= len(nums) and nums[i] != nums[nums[i]-1]:
nums[i],nums[nums[i]-1] = nums[nums[i]-1],nums[i]
for i in xrange(len(nums)):
if nums[i] != i+1:
return i+1
return nums[-1]+1
```

Second Passed

```
if not nums:
return 1
for i in xrange(len(nums)):
while 1 <= nums[i] <= len(nums) and nums[i] != nums[nums[i]-1]:
nums[nums[i]-1],nums[i] = nums[i],nums[nums[i]-1]
for i in xrange(len(nums)):
if nums[i] != i+1:
return i+1
return nums[-1]+1
```

I have checked the docs in python:https://docs.python.org/2/reference/expressions.html#evaluation-order

but I cannot see why.

BTW, the test result for the first solution is okay.