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,42 @@
/*
* @lc app=leetcode id=147 lang=java
*
* [147] Insertion Sort 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 insertionSortList(ListNode head) {
ListNode dummy = new ListNode(0);
dummy.next = null;
ListNode t;
while(head != null) {
t = head;
head = head.next;
ListNode prev = dummy;
while(true) {
if(prev.next == null || prev.next.val > t.val) {
t.next = prev.next;
prev.next = t;
break;
} else {
prev = prev.next;
}
}
}
return dummy.next;
}
}
// @lc code=end