knakul853

Untitled

Jun 27th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4. class Solution {
  5. public:
  6.     int uniquePaths(int m, int n) {
  7.        
  8.        vector<int>dp(n,1);
  9.        
  10.         for(int i=1;i<m;i++)
  11.         {
  12.             for(int j=1;j<n;j++)
  13.             {
  14.                 dp[j]+=dp[j-1];
  15.             }
  16.         }
  17.        
  18.         return dp[n-1];
  19.     }
  20. };
  21.  
  22. class Solution {
  23. public:
  24.     int uniquePaths(int m, int n) {
  25.        
  26.        vector<vector<int>>dp(m,vector<int>(n, 1));
  27.        
  28.         for(int i=1;i<m;i++)
  29.         {
  30.             for(int j=1;j<n;j++)
  31.             {
  32.                 dp[i][j] = dp[i-1][j] + dp[i][j-1];
  33.             }
  34.         }
  35.        
  36.         return dp[m-1][n-1];
  37.     }
  38. };
Add Comment
Please, Sign In to add comment