Advertisement
Guest User

Bruffo

a guest
Dec 5th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import sys
  2.  
  3. def missingInt(arr):
  4. m = sys.maxsize
  5. M = -sys.maxsize
  6.  
  7. for el in arr:
  8. if el > 0 and el < m:
  9. m = el
  10. if el > M:
  11. M = el
  12.  
  13. if m != 1:
  14. return 1
  15.  
  16. arr.append(-1)
  17. M = min(M, len(arr))
  18. i = 0
  19. while i <len(arr):
  20. if arr[i] == i:
  21. i += 1
  22. continue
  23. if arr[i] >= 1 and arr[i] <= M:
  24. temp = arr[i]
  25. if arr[temp] == temp:
  26. arr[i] = -1
  27. else:
  28. arr[i] = arr[temp]
  29. arr[temp] = temp
  30. else:
  31. arr[i] = -1
  32. i += 1
  33.  
  34. succ = 1
  35. for el in arr:
  36. if el >= 1 and el <= M:
  37. if el == succ:
  38. succ += 1
  39. else:
  40. return succ
  41. return succ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement