Your runtime beats 86.08% of java submissions


  • 0
    P
    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            
            ArrayList<Integer> list = new ArrayList<Integer>(rowIndex+1);
            if(rowIndex <0)
                return list;
            list.add(1);
            int count = (rowIndex+1)%2 ==0? (rowIndex+1)/2: (rowIndex+1)/2+1;
            for(int i =1; i<count; i++){
                long val =1;
                int k=i;
                for(int j=rowIndex; j> rowIndex-i; j--){
                    val *= j;
                    while(k>0 && val% k==0){
                      val /=k;
                    
                       k--;
                    }
                }
                list.add((int)val);
            }
            for(int i =rowIndex - count; i >=0; i--){
                list.add(list.get(i));
            }
            return list;
        }
    }
    

Log in to reply
 

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