Created
April 18, 2020 08:47
-
-
Save ABHIINAV12/c204fa04fbe9535388a6b40e3c7539d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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