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 阅读(179) 评论(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 阅读(213) 评论(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 阅读(175) 评论(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 阅读(177) 评论(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 阅读(249) 评论(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 阅读(145) 评论(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 阅读(141) 评论(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 阅读(146) 评论(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 阅读(158) 评论(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 阅读(186) 评论(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 阅读(172) 评论(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 阅读(241) 评论(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 阅读(163) 评论(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 阅读(162) 评论(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 阅读(196) 评论(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 阅读(157) 评论(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 阅读(106) 评论(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 阅读(215) 评论(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 阅读(142) 评论(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 阅读(169) 评论(0) 推荐(0) 编辑

导航