Compile error: method minimumTotal in class Solution cannot be applied to given types


  • 0
    A

    I can run my code in eclipse and get the right output of example given to us. But I keep getting compile error: Line 25: error: method minimumTotal in class Solution cannot be applied to given types; Even I skipped line 25 and there is nothing in line 25. It is so weird, could anybody help me out here? Thanks.
    If needed, I post my code here.

    public class Solution {
    public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
        if(triangle == null || triangle.size() == 0){
    			return 0;
    	}
    	int m = triangle.size();
        ArrayList<ArrayList<Integer>> dp = new ArrayList<ArrayList<Integer>>();
        ArrayList<Integer> inner = new ArrayList<Integer>();  
        inner.add((triangle.get(0)).get(0));
        dp.add(inner);
        for(int i = 1; i < m; i++) {
            inner = new ArrayList<Integer>();
            ArrayList<Integer> level = triangle.get(i);
            for(int j = 0; j < level.size(); j++) {
                if(j == 0)  {
                    inner.add(level.get(j) + dp.get(i - 1).get(j)); 
                }
                else if(j == level.size() - 1) {
                    inner.add(level.get(j) + dp.get(i - 1).get(j - 1));
                }
                else {
                    inner.add(level.get(j) + Math.min(dp.get(i - 1).get(j - 1), dp.get(i - 1).get(j)));
                }
          }
            
           dp.add(inner);
        }
         
        int ret = dp.get(m - 1).get(0);
        for(int k = 1; k < dp.get(m - 1).size(); k++) {
            ret =  Math.min(ret, dp.get(m - 1).get(k));
        }
        return ret;
    }
    

    }


  • 0
    S

    Our code definition is

    public class Solution {
        public int minimumTotal(List<List<Integer>> triangle) {
            
        }
    }
    

    But this code is using

    public class Solution {
    public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
    }
    }

Log in to reply
 

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