doc: 2025-10-24打卡

This commit is contained in:
wu xiangkai
2025-10-24 16:32:48 +08:00
parent 0540e83113
commit 6dc597fa75
5 changed files with 227 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
/*
* @lc app=leetcode id=24 lang=java
*
* [24] Swap Nodes in Pairs
*/
// @lc code=start
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode swapPairs(ListNode head) {
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode prev = dummy, cur = head, next = head == null ? null : head.next, t;
while(cur !=null && next != null) {
prev.next = next;
t = next.next;
next.next = cur;
cur.next = t;
prev = cur;
cur = cur.next;
next = cur == null ? null : cur.next;
}
return dummy.next;
}
}
// @lc code=end