feat: 2025-10-27打卡

This commit is contained in:
wu xiangkai
2025-10-27 16:22:33 +08:00
parent 6dc597fa75
commit d910c716e6
10 changed files with 501 additions and 0 deletions

43
86.partition-list.java Normal file
View File

@@ -0,0 +1,43 @@
/*
* @lc app=leetcode id=86 lang=java
*
* [86] Partition List
*/
// @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 partition(ListNode head, int x) {
ListNode tf = new ListNode(0),
tb = new ListNode(0);
tf.next = null;
tb.next = null;
ListNode cur = head, tailf = tf, tailb = tb;
while(cur != null) {
if(cur.val < x) {
tailf.next = cur;
cur = cur.next;
tailf = tailf.next;
tailf.next = null;
} else {
tailb.next = cur;
cur = cur.next;
tailb = tailb.next;
tailb.next = null;
}
}
tailf.next = tb.next;
return tf.next;
}
}
// @lc code=end