| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/feixiangcode/algorithm/master/Week_01/id_27/LeetCode_324_027.java | [Back] [Original] |
class Solution {
public void wiggleSort(int[] nums) {
int arrLen = nums.length;
int[] tmp = Arrays.copyOf(nums, arrLen);
Arrays.sort(tmp);
int pos = 0;
int smallIndex = arrLen % 2 == 0 ? arrLen / 2-1 : arrLen / 2;
int bigIndex = arrLen-1;
for (int i = smallIndex, j = bigIndex;; i--,j--) {
if (pos >= arrLen) break;
nums[pos++] = tmp[i];
if (pos>= arrLen) break;
nums[pos++] = tmp[j];
}
}
}
| Web Proxy Viewer | New URL | Original Page |