码迷,mamicode.com
首页 >  
搜索关键字:linked    ( 5490个结果
注意链表的尾部
今天做了Leetcode上面一道题Remove Duplicates from Sorted List II,要去去除链表中重复的节点,代码如下 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * ...
分类:其他好文   时间:2014-07-13 21:23:10    阅读次数:160
Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? /** * Definition for singly-linked list. * class ListNode { * int val; * ...
分类:其他好文   时间:2014-07-13 16:32:04    阅读次数:152
Insertion Sort List
不知道为什么{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
待字闺中之单链表和之恋
题目来源,待字闺中,原创@陈利人 ,欢迎大家继续关注微信公众账号“待字闺中” 原题:两个单链表(singly linked list),每一个节点里面一个0-9的数字,输入就相当于两个大数了。然后返回这两个数的和(一个新list)。这两个输入的list长度相等。 要求是:不用递归;要求算法在最好的情况下,只遍历两个list一次 ,最差的情况下两遍 分析:如果链表表示的数是从...
分类:其他好文   时间:2014-07-12 23:47:33    阅读次数:285
Leetcode: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 constant space. Y...
分类:其他好文   时间:2014-07-12 20:39:17    阅读次数:225
Leetcode--Reverse Nodes in k-Group
Problem Description: 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 left-out nodes in the...
分类:其他好文   时间:2014-07-12 19:00:26    阅读次数:235
linked-list 汇总
转+修改整理。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
【LeetCode】Insertion Sort List
题目 Sort a linked list using insertion sort. 解答 链表无法像数组那样从后往前依次比较插入,只能从前往后;在链表首部添加一个哨兵可以稍微简化下代码,代码如下: /** * Definition for singly-linked list. * public class ListNode { * int val; * ...
分类:其他好文   时间:2014-07-11 08:06:49    阅读次数:362
LeetCode——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}, reorder it t...
分类:其他好文   时间:2014-07-10 20:43:37    阅读次数:210
CTCI 2.7
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
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!