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

2015年5月11日

摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ... 阅读全文

posted @ 2015-05-11 22:17 NUST小文 阅读(113) 评论(0) 推荐(0) 编辑

摘要: For example, the following two linked lists:A: a1 → a2 ↘ c1 → c2 → c3 ↗ B:... 阅读全文

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

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) 编辑

2015年4月24日

摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".看起来挺好写的样子,没想到墨迹了半天。string add(string a, string ... 阅读全文

posted @ 2015-04-24 17:10 NUST小文 阅读(169) 评论(0) 推荐(0) 编辑

2015年4月23日

摘要: Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文

posted @ 2015-04-23 14:03 NUST小文 阅读(97) 评论(0) 推荐(0) 编辑