Remove Nth Node From End of List 描述 Given a linked list, remove the n-th node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the sec
Remove Duplicates from Sorted List 描述 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, return 1-
Remove Duplicates from Sorted List II 描述 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->
Partition List 描述 Given 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 n
Palindrome Linked List 描述 Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 分析 首先要寻找中点,原理是使用快慢指针,每次快指针走两步,慢指针走一步。同时还要用栈,每次慢指针走一步,都把值存
Odd Even Linked List 描述 Given 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 s
LRU Cache 描述 Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of t
Linked List Cycle 描述 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 分析 最容易想到的方法是,用一个哈希表unordered_map<int, bool> visited,记录每个元素是否被访问过,一旦出
Linked List Cycle II 描述 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? 分析 当 fast 与 slow 相遇时,slow
LFU Cache 描述 Design and implement a data structure for Least Frequently Used (LFU) cache. Implement the LFUCache class: LFUCache(int capacity) Initializes the object with the capacity of the data stru
Intersection of Two Linked Lists 描述 Write a program to find the node at which the intersection of two singly linked lists begins. Example 1: Input: listA = [4,1,8,4,5], listB = [5,6,1,8,4,5] Output: T
Copy List with Random Pointer 描述 A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 分析
All O(1) Data Structure 描述 Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with value 1. Or increments an existing key by 1. Key is 1. guaranteed to be a n
Add Two Numbers 描述 You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and
Add Two Numbers II 描述 You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the tw