2015年10月3日

Leetcode catalogue

摘要: 1. Array & List 1.1Sort Array的变更操作,好好运用尾指针:88题的end,75题的blueHead 88. Merge Sorted Array (Array) 75. Sort Colors 21. Merge Two Sorted Lists 23. Merge k 阅读全文

posted @ 2015-10-03 19:39 joannae 阅读(190) 评论(0) 推荐(0)

145. Binary Tree Postorder Traversal (Stack, Tree)

摘要: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, return [3,2,1]. Note: Recursive so 阅读全文

posted @ 2015-10-03 17:34 joannae 阅读(226) 评论(0) 推荐(0)

144. Binary Tree Preorder Traversal (Tree, Stack)

摘要: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3... 阅读全文

posted @ 2015-10-03 17:30 joannae 阅读(191) 评论(0) 推荐(0)

114. Flatten Binary Tree to Linked List (Stack, Tree; DFS)

摘要: Given a binary tree, flatten it to a linked list in-place. For example, Given The flattened tree should look like: 法I:递归,前序遍历 法II:迭代 每次循环,找到左子树前序遍历的最后 阅读全文

posted @ 2015-10-03 17:27 joannae 阅读(186) 评论(0) 推荐(0)

146. LRU Cache (List, HashTable)

摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the 阅读全文

posted @ 2015-10-03 16:05 joannae 阅读(256) 评论(0) 推荐(0)

142. Linked List Cycle II (List; Two-Pointers)

摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list. Follow up:Can you ... 阅读全文

posted @ 2015-10-03 15:55 joannae 阅读(156) 评论(0) 推荐(0)

141. Linked List Cycle (List; Two-Pointers)

摘要: Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space?思路:采用“快慢指针”查检查链表是否含有环。让一个指针一次走一步,另一个一次走两步... 阅读全文

posted @ 2015-10-03 15:53 joannae 阅读(152) 评论(0) 推荐(0)

125. Valid Palindrome (Array; Two-Pointers)

摘要: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Pan... 阅读全文

posted @ 2015-10-03 15:41 joannae 阅读(154) 评论(0) 推荐(0)

135. Candy(Array; Greedy)

摘要: There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following re 阅读全文

posted @ 2015-10-03 15:34 joannae 阅读(185) 评论(0) 推荐(0)

69. Sqrt(x) (Divide-and-Conquer)

摘要: Implement int sqrt(int x). Compute and return the square root of x. 注意: 计算平方的时候可能会溢出,所以mid要定义为long 另外,二分法初始上限不可能超过n/2+1 阅读全文

posted @ 2015-10-03 14:25 joannae 阅读(193) 评论(0) 推荐(0)

109. Convert Sorted List to Binary Search Tree (List; Divide-and-Conquer, dfs)

摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 也可以通过引用传递,这样就不需要先初始化。 注意,NULL是一个宏定义 #def 阅读全文

posted @ 2015-10-03 14:15 joannae 阅读(181) 评论(0) 推荐(0)

108.Convert Sorted Array to Binary Search Tree(Array; Divide-and-Conquer, dfs)

摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:使用二分法,将list的中间节点作为根节点,然后分别处理list左半边及右半边,以此递归。struc... 阅读全文

posted @ 2015-10-03 14:10 joannae 阅读(251) 评论(0) 推荐(0)

34. Search for a Range (Array; Divide-and-Conquer)

摘要: Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the or 阅读全文

posted @ 2015-10-03 11:46 joannae 阅读(176) 评论(0) 推荐(0)

35. Search Insert Position (Array; Divide-and-Conquer)

摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or 阅读全文

posted @ 2015-10-03 11:37 joannae 阅读(171) 评论(0) 推荐(0)

82. Remove Duplicates from Sorted List II (List)

摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2... 阅读全文

posted @ 2015-10-03 11:33 joannae 阅读(208) 评论(0) 推荐(0)

83. Remove Duplicates from Sorted List (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,... 阅读全文

posted @ 2015-10-03 11:31 joannae 阅读(165) 评论(0) 推荐(0)

80. Remove Duplicates from Sorted Array II (Array)

摘要: Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted array nums = [1,1,1,2,2,3], Your function s 阅读全文

posted @ 2015-10-03 11:30 joannae 阅读(124) 评论(0) 推荐(0)

143. Reorder List(List)

摘要: Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For ... 阅读全文

posted @ 2015-10-03 11:22 joannae 阅读(225) 评论(0) 推荐(0)

61. Rotate List(List)

摘要: Given 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->1->2->3->... 阅读全文

posted @ 2015-10-03 10:57 joannae 阅读(150) 评论(0) 推荐(0)

92. Reverse Linked List II (List)

摘要: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2 阅读全文

posted @ 2015-10-03 10:36 joannae 阅读(183) 评论(0) 推荐(0)

86. Partition List (List)

摘要: 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 o... 阅读全文

posted @ 2015-10-03 10:29 joannae 阅读(142) 评论(0) 推荐(0)

148. Sort List (List)

摘要: Sort a linked list in O(n log n) time using constant space complexity. 法I:快排。快排的难点在于切分序列。从头扫描,碰到>=target的元素,停止;从第二个字串扫描,碰到<=target的元素停止;交换这两个元素。这样的好处是 阅读全文

posted @ 2015-10-03 09:41 joannae 阅读(188) 评论(0) 推荐(0)

147. Insertion Sort List (List)

摘要: Sort a linked list using insertion sort. 阅读全文

posted @ 2015-10-03 09:39 joannae 阅读(152) 评论(0) 推荐(0)

128. Longest Consecutive Sequence (HashTable)

摘要: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The long 阅读全文

posted @ 2015-10-03 09:28 joannae 阅读(222) 评论(0) 推荐(0)

75. Sort Colors (Array)

摘要: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, ... 阅读全文

posted @ 2015-10-03 08:34 joannae 阅读(200) 评论(0) 推荐(0)

88. Merge Sorted Array (Array)

摘要: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size tha... 阅读全文

posted @ 2015-10-03 07:56 joannae 阅读(151) 评论(0) 推荐(0)

导航