My idea is simple. I use 'i' and 'j' to keep the current position, and use 'sum' to keep the current path sum. The 'localmin' is used to keep the minimum HP needed for each path. The 'globmin' is a global variable that is used to keep the minimum HP needed among all paths.

The code cannot pass the test case of a large input 2D matrix. I think the logic is quite similar to the DP solution, so the time complexity is also O(m*n). I know I should always use a non-recursive code if I can because it takes more memory, but can anyone tell me why this gets a TLE?

```
class Solution {
public:
int globmin = INT_MAX;
int w;
int h;
int calculateMinimumHP(vector<vector<int> > &dungeon) {
w = dungeon[0].size();
h = dungeon.size();
recurRun(dungeon, 0, 0, 0, INT_MIN);
return globmin;
}
void recurRun(vector<vector<int>>& dungeon, int i, int j, int sum, int localmin) {
if (i >= w || j >= h) return;
int currSum = sum + dungeon[j][i];
localmin = max(localmin, (currSum <= 0 ? -currSum + 1 : 0));
if (i == w - 1 && j == h - 1) { // reach princess, update the globmin
globmin = min(localmin, globmin);
return;
}
if (localmin >= globmin) return; // accelerate
// choose right
recurRun(dungeon, i + 1, j, currSum, localmin);
// choose down
recurRun(dungeon, i, j + 1, currSum, localmin);
}
};
```