5832. Array With Elements Not Equal to Average of Neighbors
5832. Array With Elements Not Equal to Average of Neighbors
Description


Solution
To generate the array in the requirement, my strategy is pickthe smallest the largest the second smallest …, because we have the largest * 2 > the sum of the smallest numbers, it should always work.
Or we can keep looping the swap the mismatched pair till we get the correct array.
Code
1 | class Solution { |
Solution 2
1 | class Solution { |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.

