title: What would be an efficient way to check duplicate answer in the following case?
body: <p>I am trying to solve this problem in leetcode: <a href="https://leetcode.com/problems/combination-sum/" rel="nofollow noreferrer">https://leetcode.com/problems/combination-sum/</a></p>
  
  <pre><code>public List&lt;List&lt;Integer&gt;&gt; combinationSum(int[] candidates, int target) 
  {
      List&lt;List&lt;Integer&gt;&gt; res = new ArrayList&lt;&gt;();
      Arrays.sort(candidates);        
      helper(candidates, target, res, new ArrayList&lt;&gt;(), 0);        
      return res;
  } 
  private void helper (int[] candidates, int target, List&lt;List&lt;Integer&gt;&gt; res, List&lt;Integer&gt; temp, int index) {
      if( target &lt; 0) return;
      if(target == 0) {
          res.add(new ArrayList&lt;&gt;(temp));
          return;
      }
  
      for(int i = index; i &lt; candidates.length; i++) {
          if(candidates[i] &gt; target) {
              return;
          }
  
          temp.add(candidates[i]);
          helper(candidates, target - candidates[i], res, temp, index);
          temp.remove(temp.size() - 1);
      }
  }
  
  For an input: candidates = [2,3,6,7], and target = 7
  My output is: [[2,2,3],[2,3,2],[3,2,2],[7]]
  Correct Output: [[2,2,3],[7]]
  </code></pre>
  
  <p>Obviously, I need to check for a duplicate before adding to the result. </p>
  
  <p>I understand I can create a set of strings where each string will be a sorted version of the list e.g., [2,3,2] => "223". This will help me to check whether I need to add the list to the result or not.</p>
  
  <p><strong>My question is what would be the best way to check for a duplicate in my situation?</strong></p>