
LeetCode LinkedList
Tech In Pieces
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode025 Reverse Nodes in k-Group
a classic one.Two Notes:Only constant extra memory is allowed.You may not alter the values in the list’s nodes, only nodes itself may be changed.although I’ve met thing problem many times, still can’t solve it.class Solution { public ListNode reve原创 2020-12-13 01:02:42 · 147 阅读 · 0 评论 -
LeetCode 链表题目中用到的高频核心代码块
链表反转核心代码:while(cur.next != null){ ListNode temp = cur.next; // cur.next = temp.next; // temp.next = pre.next; // pre.next = temp;//完成上面的四步 cur每次都停留在已经被反转的部分链表的末尾}基于原理:Input: 1->2->3->4->5->NULL其实是有三个指针。原创 2020-11-23 00:27:23 · 197 阅读 · 0 评论 -
LeetCode 23. Merge k Sorted Lists
class Solution { public ListNode mergeKLists(ListNode[] lists) {//用递归去做更好 if (lists == null || lists.length == 0) return null; PriorityQueue<ListNode> queue = new PriorityQueue<>(lists.length, (a, b) -> a.val - b.val);//t原创 2020-11-20 03:28:29 · 102 阅读 · 0 评论 -
LeetCode025 Reverse Nodes in K-Group
reverse nodes by K as a groupfirst, let’s try to use recursion method.the following code has two parts, reverseKGroup() and reverseLinkedList(). the first one is the recursion function, and the second one is a tool function which reverse a linkedlist by原创 2020-06-10 03:23:10 · 146 阅读 · 0 评论 -
LeetCode 148. Sort List (LinkedList的merger sort)
class Solution { public ListNode sortList(ListNode head) { if(head == null || head.next == null) return head; ListNode middle = getMiddle(head); ListNode l2 = middle.next; middle.next = null;原创 2020-11-20 02:54:39 · 89 阅读 · 0 评论 -
LeetCode 369. Plus One Linked List
Given a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer.Input: [1,2,3]Output: [1,2,4]idea:the one i can think of is reverse add one and reverse back.so i implemented with this:class Solution {原创 2020-11-20 01:50:43 · 132 阅读 · 0 评论 -
LeetCode 203. Remove Linked List Elements
简单的不能再简单了 但是第一次做的时候就是死心眼 认准了只用一个指针class Solution { public ListNode removeElements(ListNode head, int val) { if (head == null) return null; ListNode dummy = new ListNode(0); dummy.next = head; ListNode pre = dum原创 2020-11-19 10:48:37 · 85 阅读 · 0 评论 -
LeetCode 24. Swap Nodes in Pairs
swap in pairsclass Solution { public ListNode swapPairs(ListNode head) { if(head == null) return null; ListNode dummy = new ListNode(0); dummy.next = head; ListNode left = dummy; ListNode right = head;原创 2020-11-19 09:35:00 · 72 阅读 · 0 评论