2014年11月29日

摘要: Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?SOLUTION 1:经典快慢指针问题。如果存在环... 阅读全文
posted @ 2014-11-29 23:21 Yu's Garden 阅读(562) 评论(0) 推荐(0) 编辑
摘要: Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5... 阅读全文
posted @ 2014-11-29 23:11 Yu's Garden 阅读(486) 评论(0) 推荐(0) 编辑
摘要: Surrounded RegionsGiven a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's i... 阅读全文
posted @ 2014-11-29 22:08 Yu's Garden 阅读(1174) 评论(0) 推荐(0) 编辑
摘要: Sort ListSort a linked list in O(n log n) time using constant space complexity.使用Merge Sort, 空间复杂度是 O(logN) 因为使用了栈空间。SOLUTION 1:使用Merge Sort来解决问题。为什么不... 阅读全文
posted @ 2014-11-29 20:55 Yu's Garden 阅读(3524) 评论(4) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2014-11-29 20:23 Yu's Garden 阅读(385) 评论(0) 推荐(0) 编辑

导航