Skip to content

Instantly share code, notes, and snippets.

@ABHIINAV12
Created April 18, 2020 08:47
Show Gist options
  • Save ABHIINAV12/c204fa04fbe9535388a6b40e3c7539d7 to your computer and use it in GitHub Desktop.
Save ABHIINAV12/c204fa04fbe9535388a6b40e3c7539d7 to your computer and use it in GitHub Desktop.
class Solution {
public:
int minPathSum(vector<vector<int>>& g) {
int m=g.size();
int n=g[0].size();
for(int i=0;i<m;++i)
for(int j=0;j<n;++j){
if(i==0 && j==0)
continue;
else if(i==0){
g[i][j]+=g[i][j-1];
}else if(j==0)
g[i][j]+=g[i-1][j];
else g[i][j]+=min(g[i-1][j],g[i][j-1]);
}
return g[m-1][n-1];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment