上一页 1 ··· 9 10 11 12 13 14 下一页
摘要: 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) 编辑
摘要: 1 3Sum2 3Sum Closest3 4Sum4 Add Binary5 Add Two Numbers6 Anagrams7 Balanced Binary Tree8 Best Time to Buy and Sell Stock9 Best Time to Buy and Sell Stock II10 Best Time to Buy and Sell Stock III11 Binary Tree Inorder Traversal12 Binary Tree Level Order Traversal13 Binary Tree Level Order Traversal I 阅读全文
posted @ 2012-12-21 18:15 西施豆腐渣 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementin 阅读全文
posted @ 2012-12-21 17:55 西施豆腐渣 阅读(112) 评论(0) 推荐(0) 编辑
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 ... 阅读全文
posted @ 2012-12-21 16:21 西施豆腐渣 阅读(94) 评论(0) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings.class Solution { public: string longestCommonPrefix(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function string s; if( strs.size(... 阅读全文
posted @ 2012-12-21 05:38 西施豆腐渣 阅读(94) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.#simple way.class Solution {public: int maxProfit(vecto... 阅读全文
posted @ 2012-12-20 16:16 西施豆腐渣 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Given 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 3 Return6.key-points: globe variable record the max value of local branch.at the end, in root node compare max value cross root node w... 阅读全文
posted @ 2012-12-20 15:38 西施豆腐渣 阅读(155) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 下一页