Fast & Concise Java Solution : 8 Line 172ms O(k) space


  • 2
    R
      The basic idea is shown below (k = 3)
           step0 : 1 0 0 0
           step1 : 1 1 0 0
           step2 : 1 2 1 0
           step3 : 1 3 3 1  
    
        public List<Integer> getRow(int rowIndex) {
            int[] array = new int[rowIndex+1];
            array[0] = 1;
            for (int i = 0; i < rowIndex; ++i)
                for (int j = rowIndex; j > 0; --j)
                    array[j] += array[j-1];
            List<Integer> list = new ArrayList<Integer>(rowIndex+1);
            for (int i : array) list.add(i);
            return list;
        }

Log in to reply
 

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