摘要:
Unique Binary Search TreesGivenn, 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 / / \ ... 阅读全文
posted @ 2014-04-01 21:43
boole
阅读(125)
评论(0)
推荐(0)
摘要:
Best Time to Buy and Sell Stock IISay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not e 阅读全文
posted @ 2014-04-01 21:41
boole
阅读(111)
评论(0)
推荐(0)
摘要:
Reverse IntegerReverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321public class Solution { public int reverse(int x) { int positive = 1; int result = 0; if(x 0) { result = result*10 + x%10; x ... 阅读全文
posted @ 2014-04-01 21:40
boole
阅读(136)
评论(0)
推荐(0)
摘要:
Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode... 阅读全文
posted @ 2014-04-01 21:38
boole
阅读(113)
评论(0)
推荐(0)
摘要:
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode righ... 阅读全文
posted @ 2014-04-01 21:36
boole
阅读(77)
评论(0)
推荐(0)
摘要:
Single NumberGiven an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?public class Solution { public int singleNumber(int[] A) { int a = 0;... 阅读全文
posted @ 2014-04-01 21:35
boole
阅读(129)
评论(0)
推荐(0)
浙公网安备 33010602011771号