My Java accepted solution (210ms)


  • 0
    O
    public class Solution {
        public List<List<Integer>> generate(int numRows) {
            List<Integer> list = new ArrayList<Integer>();
    		List<List<Integer>> result = new ArrayList<List<Integer>>();
    		if (numRows == 0) {
    			return result;
    		}
    		list.add(1);
    		result.add(list);
    		List<Integer> subResult;
    		for(int i = 2; i <= numRows; i++) {
    			list = new ArrayList<Integer>();
    			subResult = result.get(i - 2);
    			list.add(1);
    			for(int j = 1; j < subResult.size(); j++) {
    				list.add(subResult.get(j - 1) + subResult.get(j));
    			}
    			list.add(1);
    			result.add(list);
    		}
    		
            return result;
        }
    }

Log in to reply
 

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