博客园  :: 首页  :: 新随笔  :: 订阅 订阅  :: 管理

2015年5月8日

摘要: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文

posted @ 2015-05-08 17:48 NUST小文 阅读(164) 评论(0) 推荐(0) 编辑

摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文

posted @ 2015-05-08 17:07 NUST小文 阅读(75) 评论(0) 推荐(0) 编辑

摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.时间复杂度为O(n)的链表环检测算法为快慢指针算法。当快慢指针相遇时,则意味着存在一个环。在检测到快慢指针指向同... 阅读全文

posted @ 2015-05-08 15:38 NUST小文 阅读(102) 评论(0) 推荐(0) 编辑

摘要: Given a linked list, determine if it has a cycle in it.快慢步,直接AC代码:值得注意一下的地方就是if(!p2->next || !p2->next->next),如果p2==NULL,那么p2->next用法是错误的,而||运算符的性质是当前... 阅读全文

posted @ 2015-05-08 11:12 NUST小文 阅读(118) 评论(0) 推荐(0) 编辑

摘要: Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.相比... 阅读全文

posted @ 2015-05-08 10:53 NUST小文 阅读(146) 评论(0) 推荐(0) 编辑

摘要: Reverse a singly linked list.比较简单,可就是如此简单,面试官让我写,我居然写错了。主要是想错了。直接上AC代码。ListNode* reverseList(ListNode* head) { if(head == NULL) retu... 阅读全文

posted @ 2015-05-08 10:09 NUST小文 阅读(146) 评论(0) 推荐(0) 编辑