knakul853

Untitled

Jul 15th, 2020
131
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.  
  5. class Solution {
  6. public:
  7.     int uniquePaths(int m, int n) {
  8.        
  9.        vector<vector<int>>dp(m,vector<int>(n, 1));
  10.        
  11.         for(int i=1;i<m;i++)
  12.         {
  13.             for(int j=1;j<n;j++)
  14.             {
  15.                 dp[i][j] = dp[i-1][j] + dp[i][j-1];
  16.             }
  17.         }
  18.        
  19.         return dp[m-1][n-1];
  20.     }
  21. };
  22.  
  23. class Solution {
  24. public:
  25.     int uniquePaths(int m, int n) {
  26.        
  27.        vector<int>dp(n,1);
  28.        
  29.         for(int i=1;i<m;i++)
  30.         {
  31.             for(int j=1;j<n;j++)
  32.             {
  33.                 dp[j]+=dp[j-1];
  34.             }
  35.         }
  36.        
  37.         return dp[n-1];
  38.     }
  39. };
Add Comment
Please, Sign In to add comment