摘要:
Set Matrix Zeroes2014.2.13 22:15Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still no 阅读全文
posted @ 2014-02-13 22:50
zhuli19901106
阅读(224)
评论(0)
推荐(0)
摘要:
Search for a Range2014.2.13 20:27Given 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 order ofO(logn).If the target is not found in the array, return[-1, -1].For example,Given[5, 7, 7, 8, 8, 10]and targ 阅读全文
posted @ 2014-02-13 20:42
zhuli19901106
阅读(176)
评论(0)
推荐(0)
摘要:
N-Queens II2014.2.13 20:01Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Solution: This problem is a simplification from the N-Queens. This time we only have record the number of solutions. Time complexity is O(n!). Space .. 阅读全文
posted @ 2014-02-13 20:22
zhuli19901106
阅读(302)
评论(0)
推荐(0)
摘要:
N-Queens2014.2.13 19:23Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct board configuration of then-queens' placement, whe 阅读全文
posted @ 2014-02-13 19:45
zhuli19901106
阅读(353)
评论(0)
推荐(0)
摘要:
LRU Cache2014.2.13 18:15Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the 阅读全文
posted @ 2014-02-13 19:20
zhuli19901106
阅读(232)
评论(0)
推荐(0)
摘要:
Longest Valid Parentheses2014.2.13 02:32Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example 阅读全文
posted @ 2014-02-13 02:43
zhuli19901106
阅读(246)
评论(0)
推荐(0)
摘要:
Insert Interval2014.2.13 01:23Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Examp 阅读全文
posted @ 2014-02-13 02:27
zhuli19901106
阅读(241)
评论(0)
推荐(0)
摘要:
Flatten Binary Tree to Linked List2014.2.13 01:03Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 ... 阅读全文
posted @ 2014-02-13 01:22
zhuli19901106
阅读(199)
评论(0)
推荐(0)
摘要:
Convert Sorted List to Binary Search Tree2014.2.13 00:46Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Solution: You may already have solved the problem Convert Sorted Array to Binary Search Tree, which can be done in O(n) time. Since l.. 阅读全文
posted @ 2014-02-13 01:00
zhuli19901106
阅读(199)
评论(0)
推荐(0)
摘要:
Binary Tree Maximum Path Sum2014.2.12 23:49Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.Solution: The maximum path sum of a tree is a path from two nodes in the tree, that... 阅读全文
posted @ 2014-02-13 00:42
zhuli19901106
阅读(485)
评论(2)
推荐(0)


浙公网安备 33010602011771号