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