Another accepted Java solution


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

  • 0
    Z

    very good idea to convert array to list. it gives faster access!


Log in to reply
 

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