随笔分类 -  Recursion

摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray[4,−1,2,1]has the largest sum =6.click to show more practice.More practice:If you have figured out the O(n) solution, try 阅读全文
posted @ 2014-02-06 03:40 Razer.Lu 阅读(535) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文
posted @ 2014-01-25 14:18 Razer.Lu 阅读(136) 评论(0) 推荐(0)
摘要:public class Solution { public double pow(double x, int n) { if(n<0){ return 1.0/powHelper(x,n); }else{ return powHelper(x, n); } } public double powHelper(double x, int n){ if(n == 0){ return 1; } double... 阅读全文
posted @ 2014-01-24 12:37 Razer.Lu 阅读(124) 评论(0) 推荐(0)