BackTracking Problems

Permutation II

Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.

有重复数字: [1,2,1]

sort, 在前一个相同数字被选之前,不能选当前数字,否则会出现 1pi, 1 == 1, 1pi的情况

Subset II

Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

The solution set must not contain duplicate subsets. Return the solution in any order.

sort,核心情况:假设第i个和第i+1个相同,当回溯从i返回,接下来循环到第i+1个时,不应该选中i+1,因为所有包含i+1的可能情况,在i的回溯中都已经遇到过了,跳过i+1

Combination Sum II

Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.

Each number in candidates may only be used once in the combination.

Note: The solution set must not contain duplicate combinations.

和combination sub的情况是一样的,核心也是当退出i的回溯时,排除掉i+1的回溯(如果i+1和i num相同,那么可以假设所有可能情况都已经考虑过了)

Palindrom String

简单回溯

总结:找到所有可能性问题,都可以考虑回溯算法

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值