不知道为什么{3,4,1}就是通不过。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), n...
分类:
其他好文 时间:
2014-07-13 12:25:11
阅读次数:
236
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...
分类:
其他好文 时间:
2014-07-12 20:39:17
阅读次数:
225
转+修改整理。import java.util.ArrayList;import java.util.Comparator;import java.util.HashMap;import java.util.PriorityQueue;import java.util.Stack;/** * htt...
分类:
其他好文 时间:
2014-07-12 13:05:27
阅读次数:
249
题目
Sort a linked list using insertion sort.
解答
链表无法像数组那样从后往前依次比较插入,只能从前往后;在链表首部添加一个哨兵可以稍微简化下代码,代码如下:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ...
分类:
其他好文 时间:
2014-07-11 08:06:49
阅读次数:
362
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...
分类:
其他好文 时间:
2014-07-10 20:43:37
阅读次数:
210
Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x.Use two addit...
分类:
其他好文 时间:
2014-07-09 17:44:36
阅读次数:
159
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the Ts d...
分类:
其他好文 时间:
2014-07-09 15:35:19
阅读次数:
176
Given a circular linked list, implement an algorithm which returns the node at the beginning of the loop.DEFINITIONCircular linked list: A (corrupt) l...
分类:
其他好文 时间:
2014-07-09 15:24:22
阅读次数:
203
Implement a function to check if a linked list is a palindrome.Reverse the second half of the list and then compare it with the first half./* Assume t...
分类:
其他好文 时间:
2014-07-09 14:25:04
阅读次数:
176
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s ...
分类:
其他好文 时间:
2014-07-08 13:34:40
阅读次数:
195