My Java Solution


  • 0
    C

    ...
    public class Solution {
    List<List<Integer>> result = new ArrayList<List<Integer>>();

    public  List<List<Integer>> generate(int numRows) {
    
    	for (int i = 0; i < numRows; i++) {
    
    		result.add(generateRow(i));
    	}
    
    	return result;
    }
    
    private  List<Integer> generateRow(int num) {
    	List<Integer> list = new ArrayList<Integer>();
    	if (num == 0) {
    		list.add(1);
    		return list;
    	}  else {
    		list.add(1);
    		for (int i = 1; i < num; i++) {
    
    			list.add(result.get(num - 1).get(i - 1) + result.get(num - 1).get(i));
    
    		}
    		list.add(1);
    	}
    
    	return list;
    }
    

    }
    ...


Log in to reply
 

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