if (n==2) { return1; } if (n==1) { return1; } if (n==0) { return0; } else { sum=sum+fib(n-1)+fib(n-2); n=n-1; } return sum; } };
Divide and conquer
Leetcode 98
又是一个medium
还是对结构体不熟
自己可能需要专门搞一下binary search tree
代码模板
1 2 3 4 5 6 7 8 9
defdivide_and_conquer(S): #(1)Divide the problem into a set of subproblem [S1,S2,...Sn]=divide(S) #2 solve the subproblem #obtain the result of subproblem ret=[divide_and_conquer(Si) for Si in [S1..Sn]] [R1,R2..Rn]=rets #3combine return combine([R1,R2,..Rn])