Skip to content

Commit 25f6820

Browse files
Create Unique Paths.cpp
1 parent 6b23658 commit 25f6820

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Medium Problems/Unique Paths.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//https://leetcode.com/problems/unique-paths/description/
2+
3+
class Solution {
4+
public:
5+
int uniquePaths(int m, int n) {
6+
vector<int>prev(n,0);
7+
for(int i=0;i<m;i++)
8+
{vector<int>temp(n,0);
9+
for(int j=0;j<n;j++)
10+
{
11+
if(i==0&&j==0)
12+
temp[j]=1;
13+
else{
14+
int l=0;
15+
int r=0;
16+
if(i>0)
17+
l=prev[j];
18+
if(j>0)
19+
r=temp[j-1];
20+
temp[j]=l+r;
21+
}
22+
}
23+
prev=temp;
24+
}
25+
return prev[n-1];
26+
}
27+
};

0 commit comments

Comments
 (0)