
linkedlist
文章平均质量分 64
baladeer
CV菜鸟
展开
-
445. 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 two numbers and return i原创 2018-01-08 11:45:15 · 115 阅读 · 0 评论 -
109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which th原创 2018-01-09 22:33:58 · 107 阅读 · 0 评论 -
83. 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->2->3. 需要注意只存在一个节点的情况, /**原创 2018-01-09 21:50:24 · 106 阅读 · 0 评论 -
203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 Credits: Special than原创 2018-01-09 21:21:32 · 109 阅读 · 0 评论 -
143. Reorder List
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 example, Given {1,2,3,4}, reorder it t原创 2018-01-09 21:20:47 · 103 阅读 · 0 评论 -
19. Remove Nth Node From End of List
Given a linked list, remove the nth 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 second node from the end, the原创 2018-01-09 11:03:02 · 109 阅读 · 0 评论 -
24. Swap Nodes in Pairs
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 algorithm should use only constant space. Y原创 2018-01-09 09:18:12 · 118 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘原创 2018-01-09 08:53:33 · 120 阅读 · 0 评论 -
92. Reverse Linked List II
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->5->NULL. Note: Given m, n satisfy the原创 2018-01-09 08:32:19 · 109 阅读 · 0 评论 -
725. Split Linked List in Parts
Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts". The length of each part should be as equal as possible: no two原创 2018-01-09 02:43:57 · 138 阅读 · 0 评论 -
328. Odd Even Linked List
这个题是把链表进行重新排序,先把奇数节点放在一起,再把偶数节点放在一起。 需要注意: odd_node->next = NULL 要写上,否则会出现错误 ** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode原创 2018-01-09 01:30:39 · 114 阅读 · 0 评论 -
234. 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? 这个题目在discussion里有人证明了空间复杂度不可能为O(1)。 /** * Definition for singly-linked list.原创 2018-01-08 21:16:16 · 111 阅读 · 0 评论 -
138. Copy List with Random Pointer 133. Clone Graph
133: /** * Definition for undirected graph. * struct UndirectedGraphNode { * int label; * vector neighbors; * UndirectedGraphNode(int x) : label(x) {}; * }; */ class Soluti原创 2018-01-08 20:43:45 · 111 阅读 · 0 评论 -
206. Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: Li原创 2018-01-08 18:39:23 · 109 阅读 · 0 评论 -
148. Sort List 21. Merge Two Sorted Lists
很好的一个模板题,链表找中点(快慢指针)和merge。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ clas原创 2018-01-08 14:00:26 · 121 阅读 · 0 评论 -
25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number o原创 2018-01-10 01:08:20 · 125 阅读 · 0 评论