Odd Even Linked List
Odd Even Linked ListGiven a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You shou
Odd Even Linked ListGiven a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You shou
Insertion Sort ListSort a linked list using insertion sort. 提示 解題應用 LinkedList Pointer Sort Insertion Sort Default:12345678910/** * Definition for singly-linked list. * type ListNode stru
Reorder ListGiven 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 example:1Given {1,2,3,4},
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 提示 解題應用 DepthFirstSearch InorderTravel
Reverse Linked List IIReverse a linked list from position m to n. Do it in-place and in one-pass. For example:123Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2-&
Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the node
Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example:12Given 1->2->3-
Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative. For example:12Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.
Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numb
Palindrome Linked ListGiven a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 提示 解題應用 LinkedList Pointer Default:12345678910/**
Reverse Linked ListReverse a singly linked list. 提示 解題應用 LinkedList Pointer Default:12345678910/** * Definition for singly-linked list. * type ListNode struct { * Val int * Nex
Remove Linked List ElementsRemove all elements from a linked list of integers that have value val. Example:12Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2
Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear only once. For example:12Given 1->1->2, return 1->2.Given 1->1->2->
Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head. For example: 1Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm s
Merge Two Sorted ListsMerge 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. 提示 解題應用 LinkedList Pointer
Remove Nth Node From End of ListGiven a linked list, remove the nth node from the end of list and return its head. Example: 123Given linked list: 1->2->3->4->5, and n = 2.After removing t