My solution with O(1) space , easy understand


  • 0
    L
    public int minimumTotal(List<List<Integer>> triangle) {
        for( int i = triangle.size()-1 ; i >= 1 ; i -- ){
            for( int j = 0 ; j < triangle.get(i-1).size() ; j ++ ){
                triangle.get(i-1).set(j, Math.min(triangle.get(i).get(j), triangle.get(i).get(j+1) ) + triangle.get(i-1).get(j) );
            }
        }
        return triangle.get(0).get(0);
    }

Log in to reply
 

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