public class Solution { public int cutRope(int target) { if(target > 60 || target < 2){ return -1; } if(target < 4){ return target - 1; } return cutRopeMax(target); } private int cutRopeMax(int target){ if(target < 5){ return target; }else{ return 3 * cutRopeMax(target - 3); } } } // public class Solution { public int cutRope(int target) { int sum = 1; if(target < 4){ return target - 1; } while(target > 4){ sum *= 3; target -= 3; } sum *= target; return sum; } }