码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode Ch5-Linked List

时间:2015-07-24 22:25:20      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:

 

1. Remove Duplicates from Sorted List II

技术分享
 1 class Solution {
 2 public:
 3     ListNode* deleteDuplicates(ListNode* head) {
 4         ListNode* dummy = new ListNode(0);
 5         dummy->next = head;
 6         ListNode* pre = dummy;
 7         ListNode* cur = head;
 8         while (cur != NULL && cur->next != NULL) {
 9             if (cur->val == cur->next->val) {
10                 while(cur->next != NULL && cur->val == cur->next->val) {
11                     cur = cur->next;            
12                 }
13                 pre->next = cur->next;
14                 cur = cur->next;
15             } else {
16                 pre = pre->next;
17                 cur = cur->next;
18             }
19         }
20         return dummy->next;
21     }
22 };
View Code

 

 

Reverse Linked List II

Partition List

Sort List

Reorder List

Merge k Sorted Lists

Copy List with Random Pointer

Convert Sorted List to Binary Search Tree

Linked List Cycle

=================================================

  24 Swap Nodes in Pairs 32.4% Medium
  148 Sort List 22.2% Medium
  61 Rotate List 21.7% Medium
  25 Reverse Nodes in k-Group 25.4% Hard
  206 Reverse Linked List 31.9% Easy
  92 Reverse Linked List II 26.0% Medium
  143 Reorder List 21.0% Medium
  19 Remove Nth Node From End of List 27.0% Easy
  203 Remove Linked List Elements 25.9% Easy
  83 Remove Duplicates from Sorted List 34.5% Easy
  82 Remove Duplicates from Sorted List II 25.0% Medium
  86 Partition List 27.4% Medium
  234 Palindrome Linked List 22.6% Easy
  21 Merge Two Sorted Lists 32.6% Easy
  23 Merge k Sorted Lists 21.1% Hard
  141 Linked List Cycle 36.3% Medium
  142 Linked List Cycle II 31.4% Medium
  160 Intersection of Two Linked Lists 28.7% Easy
  147 Insertion Sort List 26.6% Medium
  237 Delete Node in a Linked List 46.7% Easy
  138 Copy List with Random Pointer 25.2% Hard
  109 Convert Sorted List to Binary Search Tree 27.9% Medium
  2 Add Two Numbers 20.7% Medium

leetcode Ch5-Linked List

标签:

原文地址:http://www.cnblogs.com/forcheryl/p/4674458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!