Java 1 ms concise solution using double


  • 0
    Y
        public List<Integer> getRow(int rowIndex) {
            List<Integer> l = new ArrayList<>();
            for (int i = 0; i <= rowIndex; i++)
                l.add((int) Math.round(choose(rowIndex, i)));
            return l;
        }   
    
        public double choose(double n, double k) {
            double r = 1;
            for (double i = 0; i < k; i++) {
                r *= (n - i); 
                r /= (i + 1); 
            }   
            return r;
        } 
    

Log in to reply
 

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