public int minimumTotal(List<List<Integer>> triangle) {
        if (triangle == null || triangle.size() == 0) {
            return 0;
        }
        
        int[] result = new int[triangle.size()];
        result[0] = triangle.get(0).get(0);
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < triangle.size(); i++) {
            int[] newresult = new int[triangle.size()];
            for (int j = 0; j < i + 1; j++) {
                if (j == 0) {
                    newresult[j] = result[0] + triangle.get(i).get(j);
                }
                else if (j == i) {
                    newresult[j] = result[i - 1] + triangle.get(i).get(j);
                }
                else {
                    newresult[j] = Math.min(result[j-1], result[j]) + triangle.get(i).get(j);
                }
                min = Math.min(min, newresult[j]);
            }
            result = newresult;
        }
        return min;
    }