<p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>

<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on the next row.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
<strong>Output:</strong> 11
<strong>Explanation:</strong> The triangle looks like:
   <u>2</u>
  <u>3</u> 4
 6 <u>5</u> 7
4 <u>1</u> 8 3
The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> triangle = [[-10]]
<strong>Output:</strong> -10
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= triangle.length &lt;= 200</code></li>
	<li><code>triangle[0].length == 1</code></li>
	<li><code>triangle[i].length == triangle[i - 1].length + 1</code></li>
	<li><code>-10<sup>4</sup> &lt;= triangle[i][j] &lt;= 10<sup>4</sup></code></li>
</ul>

<p>&nbsp;</p>
<strong>Follow up:</strong> Could you&nbsp;do this using only <code>O(n)</code> extra space, where <code>n</code> is the total number of rows in the triangle?
class Solution {
public:
    /*
        int solve( vector<vector<int>>& triangle, int h, int p,
       vector<vector<int>>& dp){ if(h==triangle.size()) return 0;

            if(dp[h][p]!=-1) return dp[h][p];

            int a = triangle[h][p] + solve(triangle, h+1, p, dp);
            int b = triangle[h][p+1] + solve(triangle, h+1, p+1, dp);
            return dp[h][p] = min(a,b);
        }


        int minimumTotal(vector<vector<int>>& triangle) {
            if(triangle.size()==0) return 0;

            int h=triangle.size();
            int p=triangle[h-1].size();

            vector<vector<int>> dp(h+1, vector<int>(p+1,-1));
            return triangle[0][0] + solve( triangle , 1 , 0, dp);
        }
    */

    int minimumTotal(vector<vector<int>>& triangle) {
        if (triangle.size() == 0)
            return 0;

        int hh = triangle.size();
        int pp = triangle[hh - 1].size();

        vector<vector<int>> dp(hh, vector<int>(pp, 0));
        for (int p = 0; p < triangle[hh - 1].size(); p++) {
            dp[hh - 1][p] = triangle[hh - 1][p];
        }
        for (int h = hh - 2; h >= 0; h--) {
            for (int p = 0; p < triangle[h].size(); p++) {
                int a = triangle[h][p] + dp[h + 1][p];
                int b = triangle[h][p] + dp[h + 1][p + 1];
                dp[h][p] = min(a, b);
            }
        }
        return dp[0][0];
    }
};
11500