Skip to content

Commit 8deaa46

Browse files
committed
Runtime: 111 ms (Top 23.90%) | Memory: 31.1 MB (Top 16.67%)
1 parent b9f65b1 commit 8deaa46

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
// Runtime: 111 ms (Top 23.90%) | Memory: 31.1 MB (Top 16.67%)
12
class Solution {
23
public:
34
int mod=1e9+7;
45
map<pair<int,int>,pair<int,int>>h;
56
pair<int,int>solve(vector<string>&board,int i,int j,int n,int m)
67
{
7-
//base case if you reach top left then 1 path hence return 1
8+
//base case if you reach top left then 1 path hence return 1
89
if(i==0 && j==0)return {0,1};
9-
//return 0 as no path is detected
10+
//return 0 as no path is detected
1011
if(i<0 || j<0 || i>=n || j>=m || board[i][j]=='X')return {INT_MIN,0};
11-
//check if it is stored or not
12+
//check if it is stored or not
1213
if(h.find({i,j})!=h.end())return h[{i,j}];
1314
int no=0,cnt=0;
1415
if(board[i][j]!='S')no=board[i][j]-'0';
15-
//top ,left ,top left
16+
//top ,left ,top left
1617
auto a=solve(board,i-1,j,n,m);
1718
auto b=solve(board,i,j-1,n,m);
1819
auto c=solve(board,i-1,j-1,n,m);
19-
//maxi ans
20+
//maxi ans
2021
int curr=(max(a.first,max(b.first,c.first)))%mod;
21-
//if maxi ans == a , b , c then increament count of a ,b,c
22+
//if maxi ans == a , b , c then increament count of a ,b,c
2223
if(curr==a.first)cnt+=a.second;
2324
if(curr==b.first)cnt+=b.second;
2425
if(curr==c.first)cnt+=c.second;
@@ -29,4 +30,4 @@ class Solution {
2930
if(ans.first<0)return {0,0};
3031
return {ans.first%mod,ans.second%mod};
3132
}
32-
};
33+
};

0 commit comments

Comments
 (0)