gold-16-1


编写一个函数,不用临时变量,直接交换numbers = [a, b]ab的值。

示例:

输入: numbers = [1,2]
输出: [2,1]

提示:

  • numbers.length == 2
  • `-2147483647 <= numbers[i] <= 2147483647

//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int[] swapNumbers(int[] numbers) {
        return new int[] {numbers[1],numbers[0]};
    }
}
//leetcode submit region end(Prohibit modification and deletion)

文章作者: 倪春恩
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 倪春恩 !