O(1) space O(k) time java code using formular


  • 3
    A
    public class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> ans = new ArrayList<>();
        ans.add(1);
        long tmp = 1;
        for (int i = 1; i <= rowIndex; i++)
        {
            tmp = tmp * (rowIndex - i + 1) /  i ;
            ans.add((int) (tmp));
        }
        return ans;
    }
    

    }


Log in to reply
 

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