Why compile error: Line 24: error: incompatible types: int[] cannot be converted to ArrayList<Integer>


  • 0
    L
    public class Solution {
        public static ArrayList<ArrayList<Integer>> subsets(ArrayList<Integer> S) {
            // write your code here
            ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
            result.add(new ArrayList<Integer>());
            if (S == null || S.size() == 0) {
                return result;
            }
            Collections.sort(S);
    
            for(int i=0;i<S.size();++i) {
                helper(result, S, i);
            }
    
            return result;
        }
    
        private static void helper(ArrayList<ArrayList<Integer>> result, ArrayList<Integer> S, int i) {
            int len = result.size();
            int cur = S.get(i);
            for(int j=0;j<len;++j){
                ArrayList<Integer> list = result.get(j);
                ArrayList<Integer> newlist = new ArrayList<Integer>(list);
                newlist.add(cur);
                result.add(newlist);
            }
        }
    }

  • 0

    Because you changed the signature from subsets(int[] nums) to subsets(ArrayList<Integer> S).


  • 0
    L

    Thank you! I didn't realize I used the old signature


Log in to reply
 

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