Using math method, how to do with the precision and double convert to int?


  • 0
    C
    //C(m-1,m+n-2)=(m+n-2)/(m-1) * (m+n-3)/(m-2) * n/1
    
    class Solution {
        public:
            int uniquePaths(int m, int n) {
                if(!(m&&n)) return 0;
                double result=1;
                for(int i=1;i<=m-1;i++)
                {
                    result=result*(m+n-i-1)/(m-i);
                }
                return (int)result;
            }
        };
    

    Code above got WA...


Log in to reply
 

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