请解释一下[slow.next, slow, head2] = [head2, slow.next, slow]
来源:5-10 【勤于思考,夯实学习成果】阶段思考题

迷失的小麦
2021-12-15
var isPalindrome = function (head) {
if (head == null || head.next == null) {
return true
}
let slow = head
let fast = head
let prev
while (fast && fast.next) {
prev = slow
fast = fast.next.next
slow = slow.next
}
prev.next = null // 断成两个链表
// 翻转后半段
let head2 = null
while (slow) {
[slow.next, slow, head2] = [head2, slow.next, slow]
}
while (head && head2) {
if (head.val !== head2.val) {
return false
}
head = head.next
head2 = head2.next
}
return true
}
关于这个反转的代码不理解,能不能解释一下
写回答
1回答
-
lewis
2021-12-15
这是一种js语法,就是交换两个变量的值
052021-12-15
相似问题