Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. class Solution:
  2. # @param A : list of integers
  3. # Modify the array A which is passed by reference.
  4. # You do not need to return anything in this case.
  5. def arrange(self, A):
  6.  
  7. def ask(x):
  8. ret = abs(A[x])
  9. # ja perguntei ?
  10. if A[x] < 0:
  11. if A[x] == -(len(A)):
  12. return 0
  13. else:
  14. return ret
  15. elif A[x] == 0:
  16. A[x] = -len(A)
  17. A[x] = ask(0) * len(A)
  18. else:
  19. A[x] = -A[x]
  20. A[x] = ask(-A[x]) * len(A)
  21.  
  22. if A[x] == 0:
  23. A[x] = len(A) ** 2
  24. return ret
  25.  
  26.  
  27. for i in range(len(A)):
  28. # sou eu mesmo ?
  29. if A[i] == i:
  30. # sim
  31. A[i] = i * len(A)
  32. if A[i] == 0:
  33. A[i] = len(A) ** 2
  34. # nao
  35. else:
  36. # Não sei quem sou
  37. if A[i] < len(A):
  38. A[i] = -A[i]
  39. if A[i] == 0:
  40. A[i] = -len(A)
  41. A[i] = ask(A[0]) * len(A)
  42. else:
  43. A[i] = ask(-A[i]) * len(A)
  44.  
  45.  
  46. for i in range(len(A)):
  47. A[i] = A[i] / len(A)
  48. if A[i] == len(A):
  49. A[i] = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement