码迷,mamicode.com
首页 >  
搜索关键字:listnode    ( 1413个结果
LeetCode Linked List Cycle
1. 题目 Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?2.解决方案class Solution { public: bool hasCycle(ListNode *head) { if(!head){ ...
分类:其他好文   时间:2015-03-06 15:51:34    阅读次数:133
Intersection of Two Linked Lists
编程之美上有这题,先计算这两链表的长度,然后从这两链表长度相等处扫一遍,找到相同节点就跳出即可。O(n)的时间复杂度 O(1)的空间开销/** * Definition for singly-linked list. * struct ListNode { * int val; * ...
分类:其他好文   时间:2015-03-05 23:39:24    阅读次数:196
LeetCode -- Merge k Sorted Lists (Divide and Conquer / PriorityQueue)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 分支策略:每次归并两个已排好序的链表,直至只剩下一个链表。 public class Solution { public ListNode mergeKLists(List list...
分类:其他好文   时间:2015-03-05 19:33:56    阅读次数:138
【LeetCode从零单排】No83 Remove Duplicates from Sorted List
题目Given 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.代码 public static ListNode deleteD...
分类:其他好文   时间:2015-03-02 13:17:21    阅读次数:133
leetcode——Swap Nodes in Pairs
思路1: class Solution { public: // 两个指针,p, q, q指向第二个,preP是p之前 ListNode *swapPairs(ListNode *head) { if(head == NULL) return NULL; auto p = head; auto q ...
分类:其他好文   时间:2015-02-26 13:10:49    阅读次数:133
LeetcodeOJ: Merge k Sorted Lists 归并排序+最小堆
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne...
分类:编程语言   时间:2015-02-18 14:04:12    阅读次数:148
两两交换链表的结点
题目: 例如链表为1-->2-->3-->4,则交换后为:2-->1-->4-->3   代码:   #include #include typedef struct ListNode { ListNode* next; int val; }; ListNode* swapNodeInPair(ListNode* head) { /*思...
分类:其他好文   时间:2015-02-17 11:43:18    阅读次数:180
删除链表中重复的数
题目: 给定一个排序的链表,将其中重复的数全部删除。 比如:1-->1-->1-->2-->3,则返回2-->3   #include #include typedef struct ListNode { ListNode* next; int val; }; ListNode* rmDumplicateNums(ListNode* head) ...
分类:其他好文   时间:2015-02-16 22:14:07    阅读次数:168
Convert Sorted List to Binary Search Tree java
1 public TreeNode sortedListToBST(ListNode head) { 2 if(head==null) return new TreeNode(0); 3 ArrayList arr=new ArrayList(); 4 ...
分类:编程语言   时间:2015-02-16 00:20:04    阅读次数:230
leetcode_147_Insertion Sort Lis
欢迎大家阅读参考,如有错误或疑问请留言纠正,谢谢 Insertion Sort List Sort a linked list using insertion sort. class Solution { public: ListNode *insertionSortList(ListNode *head) { if( head==NULL || ...
分类:其他好文   时间:2015-02-15 12:12:01    阅读次数:175
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!