題目,對(duì)于一個(gè)數(shù)組[1,2,3,4,5,6,7],進(jìn)行奇偶索引交換,希望偶數(shù)索引都在左側(cè),奇數(shù)索引在右側(cè),得到[1,3,5,7,2,4,6]??炻羔樈夥ǎ喊凑湛炻羔樀乃枷耄苋菀子性亟粨Q的寫法: public static int[] oddEven2(int[] nums) { int n = nums.length; int l = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { swap(nums, l++, i); } } return nums; }疑問:這種交換打亂了奇數(shù)索引的順序,有沒有可以保持有序,又是原地的算法呢?