why the recursive way is out of time limit

  • 0

    I write a recursive method but it yields to time exceed error. Is it caused by calling method overhead? I do not know why and hope you guys can help me analyse the reason. Any idea is appreciated.
    public int minimumTotal(List<List<Integer>> triangle) {
    return minPath(triangle, 1, 1);
    private int minPath(List<List<Integer>> triangle, int row, int column){
    return triangle.get(row-1).get(column-1);
    return Math.min(minPath(triangle, row+1, column), minPath(triangle, row+1, column+1))+triangle.get(row-1).get(column-1);

Log in to reply

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