java using math


  • 0
    Y
    public class Solution {
        public int uniquePaths(int m, int n) {
            int max = m >= n ? m : n;
            int min = m <= n ? m : n;
            int up = m + n - 2;
            int down = n - 1;
            double solu = 1;
            for(int i = up; i > m-1; i--){
                if(down <= 1) down = 1;
                solu *= (double) i / (double)(down--);
            }
            return (int) (solu + 0.5);
        }
    }
    

Log in to reply
 

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