上一页 1 ··· 31 32 33 34 35 36 37 38 39 ··· 51 下一页
2014年2月13日
摘要: 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 阅读(344) 评论(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 阅读(226) 评论(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 阅读(230) 评论(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 阅读(232) 评论(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 阅读(189) 评论(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 阅读(192) 评论(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 阅读(475) 评论(2) 推荐(0) 编辑
2014年2月10日
摘要: Trapping Rain Water2014.2.10 03:25Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2 阅读全文
posted @ 2014-02-10 03:38 zhuli19901106 阅读(270) 评论(0) 推荐(0) 编辑
摘要: Unique Binary Search Trees II2014.2.10 02:54Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 ... 阅读全文
posted @ 2014-02-10 03:16 zhuli19901106 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Text Justification2014.2.10 02:42Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces' ' 阅读全文
posted @ 2014-02-10 02:51 zhuli19901106 阅读(359) 评论(0) 推荐(0) 编辑
上一页 1 ··· 31 32 33 34 35 36 37 38 39 ··· 51 下一页