[LeetCode] 系统刷题3_排列组合/backtracking
2019-04-11 10:23 Johnson_强生仔仔 阅读(316) 评论(0) 编辑 收藏 举报适用范围:
- 几乎所有搜索问题
- 什么时候输出
- 哪些情况需要跳过
Python library
import itertools
itertools.product('ABC', repeat = 2) 3 * 3 = 9
list(itertools.product('ABC', repeat = 2))=> [('A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'B'), ('B', 'C'), ('C', 'A'), ('C', 'B'), ('C', 'C')]
itertools.permutations('ABC', 2) 3 * 2 = 6
print(list(itertools.permutations('ABC', 2))) => [('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B')]
itertools.combinations('ABC', 2) 3
print(list(itertools.combinations('ABC', 2))) => [('A', 'B'), ('A', 'C'), ('B', 'C')]
相关题目:
Subsets/Combinations:
- [LeetCode] 78. Subsets tag: backtracking
- [LeetCode] 90.Subsets II tag: backtracking
- [LeetCode] 491. Increasing Subsequences_Medium tag: backtracking
- [LeetCode] 131. Palindrome Partitioning_Medium tag: DFS, backtracking, Palindrome
- [LeetCode] 40. Combination Sum II tag: backtracking
- [LeetCode] 39. Combination Sum_Medium tag: backtracking
- [LeetCode] 93. Restore IP Addresses_Medium tag: backtracking
- [LeetCode] 784. Letter Case Permutation_Medium tag: backtracking
- [LeetCode] 812. Largest Triangle Area_Easy tag: math
- [LeetCode] 22. Generate Parentheses_Medium tag: backtracking
Permutations:
- [LeetCode] 46. Permutations_Medium tag: DFS, backtracking
- [LeetCode] 47. Permutations II_Medium tag: DFS, backtracking
- [LeetCode] 51. N-Queens_Hard tag: DFS, backtracking
- [LeetCode] 52. N-QueensII_Hard tag: DFS, backtracking
- [LeetCode] 17. Letter Combinations of a Phone Number_Medium tag: backtracking
Backtracking