My linear time java code without cast


  • 0
    W

    Using the distributive property of multiplication to make intermediate result smaller.

    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<Integer> result = new ArrayList<Integer>();
            result.add(1);
            for (int i=1;i<=rowIndex;i++)
                result.add( result.get(i-1)/i* (rowIndex-i+1)+ result.get(i-1)%i * (rowIndex-i+1)/i);        
            return result;
        }
    }

Log in to reply
 

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