Tuesday, February 3, 2015

LeetCode [40] Combination Sum II


method1:
  • for the i-th num, choose 0 or 1, time
  • since all nums are positive, the sum of the cur is monotonously increasing
  • recursion terminates if Sum >= Target 
  • duplicate combination occurs if
    •  the i-th num == the (i-1)-th num
    • the (i-1)-th num is not selected
    • the i-th num is selected
  • use flag "sel" to notify the next iteration whether the (i-1)-th num was selected in the previous iterations
Ref:
  • dfs method

No comments:

Post a Comment