My Easy O(k) Solution (Only Ordinary Methods)


  • 1
    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<Integer> list = new ArrayList<Integer>();
            if (rowIndex < 0) return list;
            int[] row = new int[rowIndex + 1];
            for (int len = 1; len <= rowIndex + 1; len++) {
                for (int i = len - 1; i >=0; i--) {
                    if (i == len - 1 || i == 0) {
                        row[i] = 1;
                    } else {
                        row[i] += row[i - 1];
                    }
                }
            }
            for (int j = 0; j < row.length; j++) {
                list.add(row[j]);
            }
            return list;
        }
    }

Log in to reply
 

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