Triange Solution


  • 0
    V

    class Solution {
    public int minimumTotal(List<List<Integer>> triangle) {
    int no_of_rows = triangle.size();
    int[] array=new int[no_of_rows+1];
    int i=0;
    do
    { array[i]=0;
    i++; }
    while(i<no_of_rows+1);
    for(int k= no_of_rows-1; k>=0; k--)
    {
    for(int j=0; j<k+1; j++)
    {
    array[j] = Math.min(array[j], array[j+1]) + triangle.get(k).get(j);
    }
    } return array[0];
    }
    }


Log in to reply
 

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