A concise 7-line java solution. o(k)


  • 8
    2
    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            Integer[] ret = new Integer[rowIndex+1];
            Arrays.fill(ret, 0);       
            for (int i=0; i<= rowIndex; i++)
                for (int j=i; j>0; j--)
                    ret[j] = ret[j] + ret[j-1];
                ret[0] = 1;
            return Arrays.asList(ret);
        }
    }

  • 0
    K

    What happens when you input [1]?


  • 0
    W

    the answer is wrong when input 1
    add ret[0]=1 after Arrays.fill(ret, 0);


Log in to reply
 

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