I need your help


  • 0
    J
    public class Solution {
        private static int sum =0;
        public int combinationSum4(int[] nums, int target) {
            if (nums == null || nums.length ==0 || target < 0 ) return 0;
            dfs(nums, target);
            return sum;
        }
        static private void dfs(int[] nums, int remain){
            if (remain == 0) ++sum;
            else if (remain < 0) return;
            else {
                for (int i = 0; i < nums.length ; i++){
                    dfs(nums, remain - nums[i]);
                }
            }
        }
    }
    

    here's my code, I cannot pass the test case ([9], 3) when I submit, but I can pass the same case when I customize it in the window below and click run code. WHY?
    This problem wastes me 2 hours!


Log in to reply
 

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