首页 > 其他 > 详细

leetcode 343. Integer Break

时间:2016-04-20 17:39:29      阅读:274      评论:0      收藏:0      [点我收藏+]

题目:Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.

For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).

Note: you may assume that n is not less than 2.

 1 public class Solution {
 2     public int integerBreak(int n) {
 3       int result=0;
 4         if(n==2)
 5             result=1;
 6         else if(n==3)
 7             result=2;
 8         else {
 9             result = integerBreakHealper(n);
10         }
11         return result;
12         
13     }
14     public int integerBreakHealper(int n)
15     {
16         int result=0;
17         if(n==2)
18             result=2;
19         else if(n==3)
20             result=3;
21         else if(n==4)
22             result=4;
23         else {
24             result=(3*integerBreakHealper(n-3));
25         }
26         return result;
27     }
28 }

 

leetcode 343. Integer Break

原文:http://www.cnblogs.com/HelloWorld-5/p/5413482.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!