上一页 1 ··· 24 25 26 27 28 29 30 31 32 ··· 43 下一页

2015年10月3日

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 阅读(160) 评论(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) 编辑

上一页 1 ··· 24 25 26 27 28 29 30 31 32 ··· 43 下一页

导航