Course:
- 看了官方answer,Similar to my first approach,AllsortedLater in the new listappend。But I think I can’t prove the correctness,Because it is Zhou Sai dare not submit at will。
- Discover when thinking about the first solution,If I keepfor i in Whole array,Determine whether to meet the conditions and then exchange the position,What should I do if I enter the dead cycle??If a special case fails every time, it needs to be exchanged. What is the difference between random disruption??
- After watching the solution of other big guys,I am still too young
1
2
3
4
5
6
7
8
9
10def rearrangeArray(self, nums: List[int]) -> List[int]:
i = 1
while i < len(nums)-1:
if nums[i] == (nums[i - 1] + nums[i + 1]) // 2:
random.shuffle(nums)
i = 1
else:
i += 1
else:
return nums