上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 36 下一页
摘要: class Solution { public void reorderList(ListNode head) { ListNode dummyHead = new ListNode(0, head); ListNode slow = dummyHead; ListNode fast = dummy 阅读全文
posted @ 2021-12-19 17:43 振袖秋枫问红叶 阅读(26) 评论(0) 推荐(0)
摘要: 闭合为环 class Solution { public ListNode rotateRight(ListNode head, int k) { if (head == null || head.next == null || k == 0){ return head; } ListNode du 阅读全文
posted @ 2021-12-19 16:03 振袖秋枫问红叶 阅读(28) 评论(0) 推荐(0)
摘要: 两次遍历 class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { /** * 两次遍历 * 先得到链表的长度,再正向遍历到length - n的位置,也就是待删除节点的前一个节点 */ ListNode du 阅读全文
posted @ 2021-12-19 15:05 振袖秋枫问红叶 阅读(41) 评论(0) 推荐(0)
摘要: 和下一个节点交换 class Solution { public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; } } /** * 时间复杂度 O(1) * 空间复杂度 O 阅读全文
posted @ 2021-12-19 14:39 振袖秋枫问红叶 阅读(46) 评论(0) 推荐(0)
摘要: 自顶向下(递归) class Solution { public ListNode sortList(ListNode head) { return sortList(head, null); } public ListNode sortList(ListNode head, ListNode ta 阅读全文
posted @ 2021-12-19 14:23 振袖秋枫问红叶 阅读(27) 评论(0) 推荐(0)
摘要: 迭代 class Solution { public ListNode reverseKGroup(ListNode head, int k) { ListNode dummyHead = new ListNode(0, head); ListNode prev = dummyHead; ListN 阅读全文
posted @ 2021-12-17 14:44 振袖秋枫问红叶 阅读(33) 评论(0) 推荐(0)
摘要: 递归 class Solution { public ListNode insertionSortList(ListNode head) { /** * 终止条件 */ if (head == null || head.next == null){ return head; } ListNode n 阅读全文
posted @ 2021-12-17 10:21 振袖秋枫问红叶 阅读(32) 评论(0) 推荐(0)
摘要: 迭代 class Solution { public ListNode swapPairs(ListNode head) { ListNode dummyHead = new ListNode(-1, head); ListNode prev = dummyHead; ListNode cur = 阅读全文
posted @ 2021-12-16 16:08 振袖秋枫问红叶 阅读(38) 评论(0) 推荐(0)
摘要: 迭代 class Solution { public ListNode deleteDuplicates(ListNode head) { /** * 节点数小于2不用去重 */ if (head == null || head.next == null){ return head; } /** * 阅读全文
posted @ 2021-12-16 14:46 振袖秋枫问红叶 阅读(31) 评论(0) 推荐(0)
摘要: 翻转链表 class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { l1 = reverseList(l1); l2 = reverseList(l2); /** * 最后还要反转一下 */ return r 阅读全文
posted @ 2021-12-10 10:37 振袖秋枫问红叶 阅读(33) 评论(0) 推荐(0)
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 36 下一页