
leetcode-list
shanshanhi
这个作者很懒,什么都没留下…
展开
-
21. Merge Two Sorted Lists leetcode(lists)
Merge Two Sorted Lists 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. 方法一、递归的方法ListNode* mergeTwoLis...原创 2016-11-29 22:22:35 · 269 阅读 · 0 评论 -
92. Reverse Linked List II leetcode list
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原创 2016-12-26 10:17:16 · 272 阅读 · 0 评论 -
143. Reorder List leetcode list
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}, reord原创 2016-12-27 22:09:48 · 325 阅读 · 0 评论 -
148. Sort List leetcode list
Sort List Sort a linked list in O(n log n) time using constant space complexity. 本题不想做了,参考链接:(主要采用merge的思想进行做题) http://www.cnblogs.com/ganganloveu/p/3763707.html http://www.cnblogs.com/bakari/p/40转载 2016-12-27 22:18:37 · 279 阅读 · 0 评论 -
445. Add Two Numbers II leetcode (list)
Add Two Numbers II You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and原创 2016-12-22 13:15:41 · 460 阅读 · 0 评论 -
24. Swap Nodes in Pairs leetcode(list)
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 c原创 2016-12-22 11:57:25 · 355 阅读 · 0 评论 -
61. Rotate List leetcode list
Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 注意:将链表首尾相连的技巧 思路如下:将链表首尾原创 2016-12-27 21:57:36 · 300 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II leetcode list--插入头节点的重要性
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->4原创 2016-12-26 10:55:18 · 344 阅读 · 0 评论 -
链表刷题总结-技巧以及注意事项
技巧:1.插入头节点的技巧,诸如:删除链表中重复节点的题,反转链表某个区间的题等,通过插入头节点,可以使得对头节点的操作同后面节点的操作一样;2.设置一快一慢指针,诸如:判断一个链表是否有环,有环环的入口点,链表的快速排序(通过求中间节点,然后merge,递归实现的快速排序)等原创 2017-03-13 20:04:31 · 1248 阅读 · 0 评论 -
206. Reverse Linked List leetcode list
Reverse Linked ListListNode* reverseList(ListNode* head) { if(NULL == head || NULL == head->next) { return head; } ListNode* p1 = head; ListNode* p2原创 2016-12-06 21:29:16 · 245 阅读 · 0 评论 -
142. Linked List Cycle II leetcode list
Linked List Cycle II 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 solve it without using e原创 2016-12-25 22:21:03 · 278 阅读 · 0 评论 -
86. Partition List leetcode list
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 nodes原创 2016-12-25 15:24:42 · 305 阅读 · 0 评论 -
234. Palindrome Linked List leetcode list
Palindrome Linked List Given a singly linked list, determine if it is a palindrome. ollow up: Could you do it in O(n) time and O(1) space?//本题可以采用暴力解决测办法,这需要使用一个额外的栈,则时间空间复杂度均为O(n) //本处采用的思路为:首原创 2016-12-25 14:58:07 · 251 阅读 · 0 评论 -
203. Remove Linked List Elements leetcode list
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 –> 5ListNode* re原创 2016-12-06 21:31:38 · 261 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List leetcode list
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-原创 2016-12-06 21:34:43 · 277 阅读 · 0 评论 -
19. Remove Nth Node From End of List leetcode list
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原创 2016-12-06 23:03:07 · 224 阅读 · 0 评论 -
141. Linked List Cycle leetcode list
Linked List Cycle follow up: Can you solve it without using extra space?bool hasCycle(ListNode *head) { /* 加上这句就超时我也是醉了 if(NULL == head && NULL == head->next) {原创 2016-12-06 23:17:01 · 225 阅读 · 0 评论 -
160. Intersection of Two Linked Lists leetcode (list)
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原创 2016-12-22 12:11:45 · 424 阅读 · 0 评论 -
2. Add Two Numbers leetcode(list)
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 ...原创 2016-11-29 21:43:54 · 224 阅读 · 0 评论 -
328. Odd Even Linked List leetcode(list)
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 shou原创 2016-12-24 20:44:54 · 338 阅读 · 0 评论 -
109. Convert Sorted List to Binary Search Tree
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.Subscribe to see which companies asked this qu...原创 2016-12-24 21:57:49 · 337 阅读 · 0 评论 -
147. Insertion Sort List leetcode list
Insertion Sort List Sort a linked list using insertion sort. 本题为单链表的插入排序,easyListNode* insertionSortList(ListNode* head) { //本题很简单,是链表的插入排序 if(NULL == head || NULL == head->next)原创 2016-12-25 09:49:27 · 319 阅读 · 0 评论 -
单链表排序----快排 & 归并排序
题目描述: 给定一个乱序的单链表的头节点,对该链表中的节点进行排序 要求时间复杂度为O(nlgn),空间复杂度为O(1) 分析: 由于题目要求时间复杂度我O(nlgn),因此选择排序和插入排序可以排除。 在排序算法中,时间复杂度为O(nlgn)的主要有:归并排序、快速排序、堆排序。 其中堆排序的空间复杂度为(n),也不符合要求,因此也可转载 2017-10-17 18:15:59 · 896 阅读 · 0 评论