Concise Java


  • 0
    public class Solution {
        public List<List<Integer>> generate(int numRows) {
            List<List<Integer>> res = new ArrayList<>();
            if (numRows <= 0) return res;
            List<Integer> level = new ArrayList<>();
            level.add(1);
            res.add(level);
            for (int i = 0; i < numRows - 1; i++) {
                int len = level.size();
                List<Integer> temp = new ArrayList<>();
                temp.add(1);
                for (int j = 0; j < len - 1; j++) {
                    temp.add(level.get(j) + level.get(j + 1));
                }
                temp.add(1);
                level = temp;
                res.add(level);
            }
            return res;
        }
    }
    

Log in to reply
 

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