public static int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
		if (triangle == null || triangle.size() == 0) {
			return 0;
		}

		int height = triangle.size() - 1;
		int n = triangle.get(height).size();
		int[] xs = new int[n];
		int[] ys = new int[n];
		ArrayList<Integer> firstRow = triangle.get(0);
		xs[0] = firstRow.get(0);
		for (int i = 1; i <= height; i++) {
			ArrayList<Integer> row = triangle.get(i);
			ys[0] = xs[0] + row.get(0);
			int m = row.size();
			for (int j = 1; j < m - 1; j++) {
				int value = row.get(j);
				int a = xs[j - 1];
				int b = xs[j];
				ys[j] = Math.min(a + value, b + value);
			}
			ys[m - 1] = xs[m - 2] + row.get(m - 1);
			int[] tmp = ys;
			ys = xs;
			xs = tmp;
		}

		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			if (xs[i] < min) {
				min = xs[i];
			}
		}
		return min;
	}