My Concise Java Solution within 10 lines.


  • 7
    R

    My Concise Java Solution within 10 lines. Any improvement?

    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<Integer> ans = new ArrayList<Integer>();
            
            for(int i=0;i<rowIndex+1;i++){
                ans.add(1);
                for(int j=i-1;j>0;j--){
                    ans.set(j,ans.get(j)+ans.get(j-1));
                }
            }
            
            return ans;
        }
    }

Log in to reply
 

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