/*
* @lc app=leetcode.cn id=24 lang=javascript
*
* [24] 两两交换链表中的节点
*/
// @lc code=start
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var swapPairs = function(head) {
if (!head || !head.next) return head
var v1 = head, v2 = head.next, v3 = v2.next
v2.next = v1
v1.next = swapPairs(v3)
return v2
};
// @lc code=end
[24] 两两交换链表中的节点
最新推荐文章于 2024-05-29 13:40:29 发布