Java O(k) time and O(k) space solution


  • 1
    S
    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            long[] arr = new long[rowIndex+1];
            arr[0] = 1;
            for (int i = 1; i < rowIndex+1; i++) {
                arr[i] = arr[i-1] *(rowIndex-i+1)/i;
            }
            List<Integer> result = new ArrayList<Integer>();
            for (long a : arr) {
                result.add((int) a);
            }
            return result;
        }
    }

Log in to reply
 

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