Java Recurision~ of course TLE


  • 0
    B
    public class Solution {
       public int getMoneyAmount(int n){
            return getMoney(1,n);
        }
        private int getMoney(int l,int n){
            if(l>=n){
                return 0;
            }
            int max=Integer.MAX_VALUE;
            for(int i=l;i<=n;i++){
                max=Math.min(max,Math.max(getMoney(l,i-1),getMoney(i+1,n))+i);
            }
            return max;
        }
    }
    

  • 0
    P

    What would be the time complexity?

    According to me, if we do just plain recursion, it should be O(n^n).


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.