2016年12月8日 星期四

[LeetCode] 39. Combination Sum

轉自LeetCode

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
The same repeated number may be chosen from C unlimited number of times.
Note:
  • All numbers (including target) will be positive integers.
  • The solution set must not contain duplicate combinations.
For example, given candidate set [2, 3, 6, 7] and target 7,
A solution set is: 
[
  [7],
  [2, 2, 3]
]
<Solution>

要求排列組合,並且有個最終滿足條件 => DFS

這題要注意一個地方是,數字可以重複用,這點處理好就可以了

code 如下
c++

kotlin

沒有留言:

張貼留言