随笔分类 - 链表
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -
阅读全文
摘要:Given a singly linked list, determine if it is a palindrome. public class Solution { public boolean isPalindrome(ListNode head) { ListNode fast = head
阅读全文
摘要:ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5 ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val
阅读全文
摘要:看剑指offer
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? public class Solution { public boolean h
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3,
阅读全文
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. public c
阅读全文
摘要:* Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * }
阅读全文
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai
阅读全文
摘要:Given a linked list, remove the nth node from the end of list and return its head. For example, Note:Given n will always be valid.Try to do this in on
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your a
阅读全文
摘要:Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2-
阅读全文
摘要:Given a list, rotate the list to the right by k places, where k is non-negative. Example: class Solution { public ListNode rotateRight(ListNode head,
阅读全文
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal tox. You should preserve the o
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. //剑指offer删除链表中重复的结点 Fo
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. //利用归并排序的思想 class Solution { public ListNode sortList(ListNode head) { if (head
阅读全文
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For
阅读全文
摘要:Sort a linked list using insertion sort. public class Solution { public ListNode insertionSortList(ListNode head) { ListNode root = new ListNode(0); /
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up:Can you
阅读全文