[[-1],[2,3],[1,-1,-3]] Output: -2 Expected: -1 why?


  • 1
    E

    public class Solution {
    public int minimumTotal(List<List<Integer>> triangle) {

        int sum = 0;
        
        for(List<Integer> row : triangle){
            
            if(row.size() > 1){
                sum += Collections.min(row, null);
            }else{
                sum += row.get(0);
            }
        }
        return sum;
    }
    

    }


  • 1
    B

    Your code ignores the path constraint and just computes the min of each row. You want to compute the

    min path


Log in to reply
 

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