Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def missingInt(arr):
- m = sys.maxsize
- M = -sys.maxsize
- for el in arr:
- if el > 0 and el < m:
- m = el
- if el > M:
- M = el
- if m != 1:
- return 1
- arr.append(-1)
- M = min(M, len(arr))
- i = 0
- while i <len(arr):
- if arr[i] == i:
- i += 1
- continue
- if arr[i] >= 1 and arr[i] <= M:
- temp = arr[i]
- if arr[temp] == temp:
- arr[i] = -1
- else:
- arr[i] = arr[temp]
- arr[temp] = temp
- else:
- arr[i] = -1
- i += 1
- succ = 1
- for el in arr:
- if el >= 1 and el <= M:
- if el == succ:
- succ += 1
- else:
- return succ
- return succ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement