Example 1:
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Input: head = [1,2]
Output: [2,1]
以下是 Example 1 解法
static void Main(string[] args) { Reverse(); } private static void Reverse() { var nums = new int[] { 1, 2, 3, 4,5 }; Reverse(nums); Console.WriteLine($"目标阵列:{nums[0]},{nums[1]},{nums[2]},{nums[3]},{nums[4]}"); Console.ReadKey(); } private static void Reverse(int[] nums) { int left = 0; int right = nums.Length - 1; while (left < right) { int temp = nums[left]; nums[left] = nums[right]; nums[right] = temp; left++; right--; } }