my solution with o(1)


  • 0
    L

    public class Solution {

    public int uniquePaths(int m, int n) {
        if(m==1||n==1) return 1;
        int max = m>n?m:n;
        int min = m<n?m:n;
        long a = 1;
        long b = 1;
        for(int i=1;i<min;i++){
            a *= i;
            b *= (max+i-1);
        }
        return (int)(b/a);
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.