O(k) - 1 ms easy one liner inside loop, beats 89%


  • 0
    N
    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            rowIndex = rowIndex+1;
            List<Integer> ls = new ArrayList<Integer>();
            long val=1;
            for(int i=1;i<=rowIndex;i++){
                ls.add((int)(long)val);
                val = val*(rowIndex-i)/i;
            }
            return ls;
        }
    }
    

Log in to reply
 

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