链表
SYSU_xiandan
Life is like a dream.
展开
-
2. Add Two Numbers
Problem: You 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 number原创 2017-09-29 16:58:29 · 178 阅读 · 0 评论 -
206. Reverse Linked List
Problem: Reverse a singly linked list. 题目就一行,翻转一个链表。所以题目也是比较简单,我用了递归的方法实现。 Code:(LeetCode运行6ms) /** * Definition for singly-linked list. * struct ListNode { * int val; * List原创 2017-09-29 17:53:18 · 188 阅读 · 0 评论 -
92. Reverse Linked List II
Problem: 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,原创 2017-09-29 18:49:43 · 121 阅读 · 0 评论 -
86. Partition List
Problem: 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 no原创 2017-09-30 16:43:42 · 150 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
Problem: iven 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. 题意是删除链表中每个节点原创 2017-09-10 14:17:51 · 155 阅读 · 0 评论 -
61. Rotate List
Problem: 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. 由题意得,给出一个链表和一个K原创 2017-10-01 11:57:21 · 126 阅读 · 0 评论 -
24. Swap Nodes in Pairs
Problem: 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 constan原创 2017-10-02 15:32:25 · 183 阅读 · 0 评论 -
147. Insertion Sort List
Sort a linked list using insertion sort. 这一题题目比较简单,就是给出一个链表序列,然后用插入排序的方法对其进行排序。那么一般链表的操作,在前面加上dummy的话,操作起来会更简单,因为需要一个prev指针来指向前面一个位置,代码如下。 Code(LeetCode运行56ms) /** * Definition for singly-li原创 2017-12-07 11:03:05 · 121 阅读 · 0 评论