I can get the right output when I run this code, but the leetcode didn't accept it. What's the possible problem with it?

```
class Solution(object):
def missingNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
first=0
last=len(nums)-1
while first<=last:
mid=(first+last)//2
if mid<nums[mid] and (mid-1)==nums[mid-1]:
break
elif mid<nums[mid] and (mid-1)<nums[mid-1]:
last=mid-1
elif mid==nums[mid]:
first=mid+1
return mid
```