Find how many combinations(ways), and use integer's binary string to store going left or going right, but it failed

  • 0
    import java.util.*;
    public class Solution {
        public int minimumTotal(List<List<Integer>> triangle) {
        	int size = triangle.size();
        	int ways = (int)Math.pow(2, size-1);
        	int globalMin = Integer.MAX_VALUE;
        	int counter = ways-1;
        	int bitLength =size-1;
        	for(int i = counter;i>=0;i--){
        		int tempSum=triangle.get(0).get(0);
        		for(int j = 0;j<=bitLength-1;j++){
        				tempSum += triangle.get(j+1).get(j+1);
        				tempSum += triangle.get(j+1).get(j);
        			globalMin = tempSum;
        	return globalMin;

Log in to reply

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