摘要: Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2, 阅读全文
posted @ 2016-07-04 05:29 北叶青藤 阅读(238) 评论(0) 推荐(0) 编辑
摘要: For a given sorted array (ascending order) and a target number, find the first index of this number in O(log n) time complexity. If the target number 阅读全文
posted @ 2016-07-04 01:22 北叶青藤 阅读(238) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it. Given a linked list, determine if it has a cycle in it. Given a linked list, determine if it h 阅读全文
posted @ 2016-07-03 11:45 北叶青藤 阅读(188) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list L: L0 → L1 → … → Ln-1 → Ln reorder it to: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → … Example Given 1->2->3->4->null, reorder it to 阅读全文
posted @ 2016-07-03 10:33 北叶青藤 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list in O(n log n) time using constant space complexity. Example Given 1->3->2->null, sort it to 1->2->3->null. Merge Sort version 1 /** 阅读全文
posted @ 2016-07-03 10:24 北叶青藤 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the 阅读全文
posted @ 2016-07-03 08:03 北叶青藤 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Reverse Linked List I Reverse a linked list. Example For linked list 1->2->3, the reversed linked list is 3->2->1 分析: 典型的3 pointers 问题。 1 /** 2 * Defi 阅读全文
posted @ 2016-07-03 07:32 北叶青藤 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 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 @ 2016-07-03 06:55 北叶青藤 阅读(172) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. Example 2 1->2->3 => / \ 1 3 分析:非常简单,用递归 阅读全文
posted @ 2016-07-03 06:00 北叶青藤 阅读(244) 评论(0) 推荐(0) 编辑
摘要: Remove Duplicates from Sorted List I Given a sorted linked list, delete all duplicates such that each element appear only once. Remove Duplicates from 阅读全文
posted @ 2016-07-03 04:36 北叶青藤 阅读(191) 评论(0) 推荐(0) 编辑