Mathematics ways for Java, bet 88% code


  • 4
    T
    public List<Integer> getRow(int rowIndex) {
        List<Integer> res = new ArrayList<>();
        res.add(1);
        int k = rowIndex;
        for( int i = 1; i <= rowIndex; i++, k-- ){
            // Using double to remove the overflow
            double tmp = ((double)res.get(i-1)*k)/i;
            res.add( (int)tmp );
        }
        return res;
    }

Log in to reply
 

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