面试题 16.01. 交换数字 Posted on 2020-04-02 | In leetcode Words count in article: 84 | Reading time ≈ 1 题目编写一个函数,不用临时变量,直接交换numbers = [a, b]中a与b的值。 示例1:12输入: numbers = [1,2]输出: [2,1] 提示:numbers.length == 2 解法解法一:使用位运算符 JAVA123456public int[] swapNumbers(int[] numbers) { numbers[0] = numbers[0] ^ numbers[1]; numbers[1] = numbers[0] ^ numbers[1]; numbers[0] = numbers[0] ^ numbers[1]; return numbers; }