Is there any problem with this snippet?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sjoytu
    New Member
    • Feb 2018
    • 1

    Is there any problem with this snippet?

    Code:
    /**
     * 
     * @param row The ith row of the Pascal Triangle
     * @return ArrayList<Integer> A List containing all the binomial coefficients
     *         for the given row
     */   
    public ArrayList<Integer> pascalRow(int row){
        ArrayList<Integer> values = new ArrayList<Integer>();
        
        for(int i = 0; i <= row; i++){
            values.add(choose(row, i));
        }
        
        return values;
    
    }
    
    /**
     * 
     * @param n The number of total elements
     * @param r The number to choose from n
     * @return The binomial coefficient n!/(r! * (n-r)!)
     */
    public int choose(int n, int r){
        return factorial(n)/(factorial(r) * factorial(n-r));
    }
    
    /**
     * 
     * @param n The number of which to take the factorial
     * @return int n!
     */
    public int factorial(int n){
        int x = 1;
        
        for(int i = 2; i <= n; i++){
            x *= i;
        }
        
        return x;
    }
    Source https://txeditor.com/jhn9g440ob5
Working...