Skip to content

Commit ed10fa3

Browse files
authored
Create Gold Mine Problem.cpp
1 parent f59a4fb commit ed10fa3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Gold Mine Problem.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution{
2+
public:
3+
int maxGold(int n, int m, vector<vector<int>> M)
4+
{
5+
// code here
6+
int ans=0;
7+
for(int j=1;j<m;j++){
8+
for(int i=0;i<n;i++){
9+
int mx=INT_MIN;
10+
if(i-1>=0 and j-1>=0) mx=max(mx,M[i-1][j-1]);
11+
if(j-1>=0) mx=max(mx,M[i][j-1]);
12+
if(i+1<n and j-1>=0) mx=max(mx,M[i+1][j-1]);
13+
M[i][j]+=mx;
14+
ans=max(ans,M[i][j]);
15+
}
16+
}
17+
return ans;
18+
}
19+
};

0 commit comments

Comments
 (0)