摘要: Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.incomplete.class Solution { public: int firstMissingPositive(int A[], int n) { // Start typing your ... 阅读全文
posted @ 2012-12-22 13:42 西施豆腐渣 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution ... 阅读全文
posted @ 2012-12-22 13:40 西施豆腐渣 阅读(101) 评论(0) 推荐(0) 编辑
摘要: Write a function isBST(BinaryTree *node) to verify if a given binary tree is a Binary Search Tree (BST) or not1. every node must be greater than left node and less than right node.2. also must be less than parent if left child or greater than parent if right child.java 1. (NULL null) 2. (-> .) 3. 阅读全文
posted @ 2012-12-22 13:02 西施豆腐渣 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).Note:Bonus po... 阅读全文
posted @ 2012-12-22 11:19 西施豆腐渣 阅读(141) 评论(0) 推荐(0) 编辑
摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many possible uni 阅读全文
posted @ 2012-12-22 07:53 西施豆腐渣 阅读(131) 评论(0) 推荐(0) 编辑