1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne...
分类:
其他好文 时间:
2014-11-22 22:45:56
阅读次数:
190
这个题目其实不难的,主要是我C++的水平太差了,链表那里绊了好久,但是又不像用python,所以还是强行上了。 题目如下: Given a sorted linked list, delete all duplicates such that each element appear only onc...
分类:
其他好文 时间:
2014-11-22 17:16:55
阅读次数:
177
ProblemImplement an algorithm to find the kth to last element of a singly linked list.Solution 1 public static ListNode findElement(ListNode head, int...
分类:
其他好文 时间:
2014-11-22 10:38:33
阅读次数:
168
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then le...
分类:
其他好文 时间:
2014-11-22 07:04:50
阅读次数:
136
Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2-...
分类:
其他好文 时间:
2014-11-21 18:16:43
阅读次数:
271
目录:
1、题目及分析
1.1 题目
1.2 分析
1、题目及分析
1.1 题目:
Sort a linked list in O(n log n)
time using constant space complexity.
1.2 分析
O(n log n)的复杂度,所以不能采用冒泡等,这里采用合并排序算法,且为了不采用递归的方式,...
分类:
其他好文 时间:
2014-11-21 16:17:51
阅读次数:
138
题目描述:
Sort a linked list using insertion sort.
思路:在head之前插入一个假头结点,便于在head节点之前插值。遍历链表,对于每一个节点,在它前面的有序的节点中找到第一个比它大的节点,将它插到该节点的前面。链表遍历结束后即得到有序链表。
代码:
ListNode * Solution::insertionSortList(...
分类:
其他好文 时间:
2014-11-21 10:38:31
阅读次数:
148
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 al...
分类:
其他好文 时间:
2014-11-21 06:55:40
阅读次数:
187
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?这道题用来判断链表中是否有循环,最开始我想的是遍历链表,同时用一个list保存遍历过...
分类:
其他好文 时间:
2014-11-21 01:18:32
阅读次数:
203
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?这道题要用双指针,但我想试一下投机取巧的办法行不行...
分类:
其他好文 时间:
2014-11-20 21:46:01
阅读次数:
185