public static int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
    	if(triangle == null) return 0;
    	int[] prev = new int[1];
    	prev[0] = triangle.get(0).get(0);
    	int min = prev[0];
    	int i =1;
        while(i< triangle.size()){
        	int[] cur = new int[triangle.get(i).size()];
        	cur[0] = prev[0] +  triangle.get(i).get(0);
        	min = cur[0];
        	for(int j = 0; j< prev.length-1; j++){
        		if(prev[j] < prev[j+1]){
        			cur[j+1] = triangle.get(i).get(j+1)+prev[j];
        		}
        		else{
        			cur[j+1] = triangle.get(i).get(j+1) + prev[j+1];
        		}
        		if( min > cur[j+1] ) min = cur[j+1];
        	}
        	cur[cur.length-1] = prev[prev.length-1]+ triangle.get(i).get(triangle.get(i).size()-1);
        	if(min > cur[cur.length-1]) min = cur[cur.length-1];
        	prev = cur;
        	i++;
        }
        return min;
    }