@ -1902,16 +1902,23 @@
< a id = "__codelineno-0-10" name = "__codelineno-0-10" href = "#__codelineno-0-10" > < / a > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > choice< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-0-11" name = "__codelineno-0-11" href = "#__codelineno-0-11" > < / a > < span class = "w" > < / span > < span class = "c1" > // 剪枝:不允许重复选择元素 且 不允许重复选择相等元素< / span >
< a id = "__codelineno-0-12" name = "__codelineno-0-12" href = "#__codelineno-0-12" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-0-13" name = "__codelineno-0-13" href = "#__codelineno-0-13" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试< / span >
< a id = "__codelineno-0-14" name = "__codelineno-0-14" href = "#__codelineno-0-14" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > true< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 做出选择< / span >
< a id = "__codelineno-0-15" name = "__codelineno-0-15" href = "#__codelineno-0-15" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 更新状态< / span >
< a id = "__codelineno-0-13" name = "__codelineno-0-13" href = "#__codelineno-0-13" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试:做出选择,更新状态 < / span >
< a id = "__codelineno-0-14" name = "__codelineno-0-14" href = "#__codelineno-0-14" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > true< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-0-15" name = "__codelineno-0-15" href = "#__codelineno-0-15" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span >
< a id = "__codelineno-0-16" name = "__codelineno-0-16" href = "#__codelineno-0-16" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-0-17" name = "__codelineno-0-17" href = "#__codelineno-0-17" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退< / span >
< a id = "__codelineno-0-18" name = "__codelineno-0-18" href = "#__codelineno-0-18" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > false< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 撤销选择< / span >
< a id = "__codelineno-0-19" name = "__codelineno-0-19" href = "#__codelineno-0-19" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > remove< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > size< / span > < span class = "p" > ()< / span > < span class = "w" > < / span > < span class = "o" > -< / span > < span class = "w" > < / span > < span class = "mi" > 1< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 恢复到之前的状态< / span >
< a id = "__codelineno-0-17" name = "__codelineno-0-17" href = "#__codelineno-0-17" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退:撤销选择,恢复到之前的状态 < / span >
< a id = "__codelineno-0-18" name = "__codelineno-0-18" href = "#__codelineno-0-18" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > false< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-0-19" name = "__codelineno-0-19" href = "#__codelineno-0-19" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > remove< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > size< / span > < span class = "p" > ()< / span > < span class = "w" > < / span > < span class = "o" > -< / span > < span class = "w" > < / span > < span class = "mi" > 1< / span > < span class = "p" > );< / span >
< a id = "__codelineno-0-20" name = "__codelineno-0-20" href = "#__codelineno-0-20" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-0-21" name = "__codelineno-0-21" href = "#__codelineno-0-21" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-0-22" name = "__codelineno-0-22" href = "#__codelineno-0-22" > < / a > < span class = "p" > }< / span >
< a id = "__codelineno-0-23" name = "__codelineno-0-23" href = "#__codelineno-0-23" > < / a >
< a id = "__codelineno-0-24" name = "__codelineno-0-24" href = "#__codelineno-0-24" > < / a > < span class = "cm" > /* 全排列 I */< / span >
< a id = "__codelineno-0-25" name = "__codelineno-0-25" href = "#__codelineno-0-25" > < / a > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "nf" > permutationsI< / span > < span class = "p" > (< / span > < span class = "kt" > int< / span > < span class = "o" > []< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-0-26" name = "__codelineno-0-26" href = "#__codelineno-0-26" > < / a > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > ArrayList< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > > < / span > < span class = "p" > ();< / span >
< a id = "__codelineno-0-27" name = "__codelineno-0-27" href = "#__codelineno-0-27" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > ArrayList< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > < / span > < span class = "p" > (),< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "kt" > boolean< / span > < span class = "o" > [< / span > < span class = "n" > nums< / span > < span class = "p" > .< / span > < span class = "na" > length< / span > < span class = "o" > ]< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-0-28" name = "__codelineno-0-28" href = "#__codelineno-0-28" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-0-29" name = "__codelineno-0-29" href = "#__codelineno-0-29" > < / a > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
@ -1927,16 +1934,25 @@
< a id = "__codelineno-1-10" name = "__codelineno-1-10" href = "#__codelineno-1-10" > < / a > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > choice< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ];< / span >
< a id = "__codelineno-1-11" name = "__codelineno-1-11" href = "#__codelineno-1-11" > < / a > < span class = "w" > < / span > < span class = "c1" > // 剪枝:不允许重复选择元素 且 不允许重复选择相等元素< / span >
< a id = "__codelineno-1-12" name = "__codelineno-1-12" href = "#__codelineno-1-12" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ])< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-1-13" name = "__codelineno-1-13" href = "#__codelineno-1-13" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试< / span >
< a id = "__codelineno-1-14" name = "__codelineno-1-14" href = "#__codelineno-1-14" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > true< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 做出选择< / span >
< a id = "__codelineno-1-15" name = "__codelineno-1-15" href = "#__codelineno-1-15" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > push_back< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 更新状态< / span >
< a id = "__codelineno-1-13" name = "__codelineno-1-13" href = "#__codelineno-1-13" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试:做出选择,更新状态 < / span >
< a id = "__codelineno-1-14" name = "__codelineno-1-14" href = "#__codelineno-1-14" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > true< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-1-15" name = "__codelineno-1-15" href = "#__codelineno-1-15" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > push_back< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span >
< a id = "__codelineno-1-16" name = "__codelineno-1-16" href = "#__codelineno-1-16" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-1-17" name = "__codelineno-1-17" href = "#__codelineno-1-17" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退< / span >
< a id = "__codelineno-1-18" name = "__codelineno-1-18" href = "#__codelineno-1-18" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > false< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 撤销选择< / span >
< a id = "__codelineno-1-19" name = "__codelineno-1-19" href = "#__codelineno-1-19" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > pop_back< / span > < span class = "p" > ();< / span > < span class = "w" > < / span > < span class = "c1" > // 恢复到之前的状态< / span >
< a id = "__codelineno-1-17" name = "__codelineno-1-17" href = "#__codelineno-1-17" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退:撤销选择,恢复到之前的状态 < / span >
< a id = "__codelineno-1-18" name = "__codelineno-1-18" href = "#__codelineno-1-18" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > false< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-1-19" name = "__codelineno-1-19" href = "#__codelineno-1-19" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > pop_back< / span > < span class = "p" > ();< / span >
< a id = "__codelineno-1-20" name = "__codelineno-1-20" href = "#__codelineno-1-20" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-1-21" name = "__codelineno-1-21" href = "#__codelineno-1-21" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-1-22" name = "__codelineno-1-22" href = "#__codelineno-1-22" > < / a > < span class = "p" > }< / span >
< a id = "__codelineno-1-23" name = "__codelineno-1-23" href = "#__codelineno-1-23" > < / a >
< a id = "__codelineno-1-24" name = "__codelineno-1-24" href = "#__codelineno-1-24" > < / a > < span class = "cm" > /* 全排列 I */< / span >
< a id = "__codelineno-1-25" name = "__codelineno-1-25" href = "#__codelineno-1-25" > < / a > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > permutationsI< / span > < span class = "p" > (< / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-1-26" name = "__codelineno-1-26" href = "#__codelineno-1-26" > < / a > < span class = "w" > < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-1-27" name = "__codelineno-1-27" href = "#__codelineno-1-27" > < / a > < span class = "w" > < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > bool< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > (< / span > < span class = "n" > nums< / span > < span class = "p" > .< / span > < span class = "n" > size< / span > < span class = "p" > (),< / span > < span class = "w" > < / span > < span class = "nb" > false< / span > < span class = "p" > );< / span >
< a id = "__codelineno-1-28" name = "__codelineno-1-28" href = "#__codelineno-1-28" > < / a > < span class = "w" > < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-1-29" name = "__codelineno-1-29" href = "#__codelineno-1-29" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-1-30" name = "__codelineno-1-30" href = "#__codelineno-1-30" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-1-31" name = "__codelineno-1-31" href = "#__codelineno-1-31" > < / a > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
@ -1952,41 +1968,87 @@
< a id = "__codelineno-2-10" name = "__codelineno-2-10" href = "#__codelineno-2-10" > < / a > < span class = "k" > for< / span > < span class = "n" > i< / span > < span class = "p" > ,< / span > < span class = "n" > choice< / span > < span class = "ow" > in< / span > < span class = "nb" > enumerate< / span > < span class = "p" > (< / span > < span class = "n" > choices< / span > < span class = "p" > ):< / span >
< a id = "__codelineno-2-11" name = "__codelineno-2-11" href = "#__codelineno-2-11" > < / a > < span class = "c1" > # 剪枝:不允许重复选择元素< / span >
< a id = "__codelineno-2-12" name = "__codelineno-2-12" href = "#__codelineno-2-12" > < / a > < span class = "k" > if< / span > < span class = "ow" > not< / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]:< / span >
< a id = "__codelineno-2-13" name = "__codelineno-2-13" href = "#__codelineno-2-13" > < / a > < span class = "c1" > # 尝试< / span >
< a id = "__codelineno-2-14" name = "__codelineno-2-14" href = "#__codelineno-2-14" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > True< / span > < span class = "c1" > # 做出选择< / span >
< a id = "__codelineno-2-15" name = "__codelineno-2-15" href = "#__codelineno-2-15" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > append< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > )< / span > < span class = "c1" > # 更新状态< / span >
< a id = "__codelineno-2-13" name = "__codelineno-2-13" href = "#__codelineno-2-13" > < / a > < span class = "c1" > # 尝试:做出选择,更新状态 < / span >
< a id = "__codelineno-2-14" name = "__codelineno-2-14" href = "#__codelineno-2-14" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > True< / span >
< a id = "__codelineno-2-15" name = "__codelineno-2-15" href = "#__codelineno-2-15" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > append< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > )< / span >
< a id = "__codelineno-2-16" name = "__codelineno-2-16" href = "#__codelineno-2-16" > < / a > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "n" > res< / span > < span class = "p" > )< / span >
< a id = "__codelineno-2-17" name = "__codelineno-2-17" href = "#__codelineno-2-17" > < / a > < span class = "c1" > # 回退< / span >
< a id = "__codelineno-2-18" name = "__codelineno-2-18" href = "#__codelineno-2-18" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > False< / span > < span class = "c1" > # 撤销选择< / span >
< a id = "__codelineno-2-19" name = "__codelineno-2-19" href = "#__codelineno-2-19" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > ()< / span > < span class = "c1" > # 恢复到之前的状态< / span >
< a id = "__codelineno-2-17" name = "__codelineno-2-17" href = "#__codelineno-2-17" > < / a > < span class = "c1" > # 回退:撤销选择,恢复到之前的状态< / span >
< a id = "__codelineno-2-18" name = "__codelineno-2-18" href = "#__codelineno-2-18" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > False< / span >
< a id = "__codelineno-2-19" name = "__codelineno-2-19" href = "#__codelineno-2-19" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > ()< / span >
< a id = "__codelineno-2-20" name = "__codelineno-2-20" href = "#__codelineno-2-20" > < / a >
< a id = "__codelineno-2-21" name = "__codelineno-2-21" href = "#__codelineno-2-21" > < / a > < span class = "k" > def< / span > < span class = "nf" > permutations_i< / span > < span class = "p" > (< / span > < span class = "n" > nums< / span > < span class = "p" > :< / span > < span class = "nb" > list< / span > < span class = "p" > [< / span > < span class = "nb" > int< / span > < span class = "p" > ])< / span > < span class = "o" > -> < / span > < span class = "nb" > list< / span > < span class = "p" > [< / span > < span class = "nb" > list< / span > < span class = "p" > [< / span > < span class = "nb" > int< / span > < span class = "p" > ]]:< / span >
< a id = "__codelineno-2-22" name = "__codelineno-2-22" href = "#__codelineno-2-22" > < / a > < span class = "w" > < / span > < span class = "sd" > " " " 全排列 I" " " < / span >
< a id = "__codelineno-2-23" name = "__codelineno-2-23" href = "#__codelineno-2-23" > < / a > < span class = "n" > res< / span > < span class = "o" > =< / span > < span class = "p" > []< / span >
< a id = "__codelineno-2-24" name = "__codelineno-2-24" href = "#__codelineno-2-24" > < / a > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "o" > =< / span > < span class = "p" > [],< / span > < span class = "n" > choices< / span > < span class = "o" > =< / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "n" > selected< / span > < span class = "o" > =< / span > < span class = "p" > [< / span > < span class = "kc" > False< / span > < span class = "p" > ]< / span > < span class = "o" > *< / span > < span class = "nb" > len< / span > < span class = "p" > (< / span > < span class = "n" > nums< / span > < span class = "p" > ),< / span > < span class = "n" > res< / span > < span class = "o" > =< / span > < span class = "n" > res< / span > < span class = "p" > )< / span >
< a id = "__codelineno-2-25" name = "__codelineno-2-25" href = "#__codelineno-2-25" > < / a > < span class = "k" > return< / span > < span class = "n" > res< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_i.go< / span > < pre > < span > < / span > < code > < a id = "__codelineno-3-1" name = "__codelineno-3-1" href = "#__codelineno-3-1" > < / a > < span class = "p" > [< / span > < span class = "nx" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-3-2" name = "__codelineno-3-2" href = "#__codelineno-3-2" > < / a >
< a id = "__codelineno-3-3" name = "__codelineno-3-3" href = "#__codelineno-3-3" > < / a > < span class = "p" > [< / span > < span class = "nx" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > permutationsI< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_i.js< / span > < pre > < span > < / span > < code > < a id = "__codelineno-4-1" name = "__codelineno-4-1" href = "#__codelineno-4-1" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-4-2" name = "__codelineno-4-2" href = "#__codelineno-4-2" > < / a >
< a id = "__codelineno-4-3" name = "__codelineno-4-3" href = "#__codelineno-4-3" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > permutationsI< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_i.ts< / span > < pre > < span > < / span > < code > < a id = "__codelineno-5-1" name = "__codelineno-5-1" href = "#__codelineno-5-1" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-5-2" name = "__codelineno-5-2" href = "#__codelineno-5-2" > < / a >
< a id = "__codelineno-5-3" name = "__codelineno-5-3" href = "#__codelineno-5-3" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > permutationsI< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_i.c< / span > < pre > < span > < / span > < code > < a id = "__codelineno-6-1" name = "__codelineno-6-1" href = "#__codelineno-6-1" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-6-2" name = "__codelineno-6-2" href = "#__codelineno-6-2" > < / a >
< a id = "__codelineno-6-3" name = "__codelineno-6-3" href = "#__codelineno-6-3" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > permutationsI< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_i.cs< / span > < pre > < span > < / span > < code > < a id = "__codelineno-7-1" name = "__codelineno-7-1" href = "#__codelineno-7-1" > < / a > < span class = "na" > [class]< / span > < span class = "p" > {< / span > < span class = "n" > permutations_i< / span > < span class = "p" > }< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< div class = "highlight" > < span class = "filename" > permutations_i.cs< / span > < pre > < span > < / span > < code > < a id = "__codelineno-7-1" name = "__codelineno-7-1" href = "#__codelineno-7-1" > < / a > < span class = "cm" > /* 回溯算法:全排列 I */< / span >
< a id = "__codelineno-7-2" name = "__codelineno-7-2" href = "#__codelineno-7-2" > < / a > < span class = "k" > void< / span > < span class = "w" > < / span > < span class = "nf" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "p" > []< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "kt" > bool< / span > < span class = "p" > []< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-7-3" name = "__codelineno-7-3" href = "#__codelineno-7-3" > < / a > < span class = "w" > < / span > < span class = "c1" > // 当状态长度等于元素数量时,记录解< / span >
< a id = "__codelineno-7-4" name = "__codelineno-7-4" href = "#__codelineno-7-4" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > Count< / span > < span class = "w" > < / span > < span class = "o" > ==< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > .< / span > < span class = "n" > Length< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-7-5" name = "__codelineno-7-5" href = "#__codelineno-7-5" > < / a > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > .< / span > < span class = "n" > Add< / span > < span class = "p" > (< / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ));< / span >
< a id = "__codelineno-7-6" name = "__codelineno-7-6" href = "#__codelineno-7-6" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-7-7" name = "__codelineno-7-7" href = "#__codelineno-7-7" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-7-8" name = "__codelineno-7-8" href = "#__codelineno-7-8" > < / a > < span class = "w" > < / span > < span class = "c1" > // 遍历所有选择< / span >
< a id = "__codelineno-7-9" name = "__codelineno-7-9" href = "#__codelineno-7-9" > < / a > < span class = "w" > < / span > < span class = "k" > for< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > i< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "m" > 0< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "n" > i< / span > < span class = "w" > < / span > < span class = "o" > < < / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > .< / span > < span class = "n" > Length< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "n" > i< / span > < span class = "o" > ++< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-7-10" name = "__codelineno-7-10" href = "#__codelineno-7-10" > < / a > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > choice< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ];< / span >
< a id = "__codelineno-7-11" name = "__codelineno-7-11" href = "#__codelineno-7-11" > < / a > < span class = "w" > < / span > < span class = "c1" > // 剪枝:不允许重复选择元素 且 不允许重复选择相等元素< / span >
< a id = "__codelineno-7-12" name = "__codelineno-7-12" href = "#__codelineno-7-12" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ])< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-7-13" name = "__codelineno-7-13" href = "#__codelineno-7-13" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试:做出选择,更新状态< / span >
< a id = "__codelineno-7-14" name = "__codelineno-7-14" href = "#__codelineno-7-14" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > true< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-7-15" name = "__codelineno-7-15" href = "#__codelineno-7-15" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > Add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span >
< a id = "__codelineno-7-16" name = "__codelineno-7-16" href = "#__codelineno-7-16" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-7-17" name = "__codelineno-7-17" href = "#__codelineno-7-17" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退:撤销选择,恢复到之前的状态< / span >
< a id = "__codelineno-7-18" name = "__codelineno-7-18" href = "#__codelineno-7-18" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > false< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-7-19" name = "__codelineno-7-19" href = "#__codelineno-7-19" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > RemoveAt< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > Count< / span > < span class = "w" > < / span > < span class = "o" > -< / span > < span class = "w" > < / span > < span class = "m" > 1< / span > < span class = "p" > );< / span >
< a id = "__codelineno-7-20" name = "__codelineno-7-20" href = "#__codelineno-7-20" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-7-21" name = "__codelineno-7-21" href = "#__codelineno-7-21" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-7-22" name = "__codelineno-7-22" href = "#__codelineno-7-22" > < / a > < span class = "p" > }< / span >
< a id = "__codelineno-7-23" name = "__codelineno-7-23" href = "#__codelineno-7-23" > < / a >
< a id = "__codelineno-7-24" name = "__codelineno-7-24" href = "#__codelineno-7-24" > < / a > < span class = "cm" > /* 全排列 I */< / span >
< a id = "__codelineno-7-25" name = "__codelineno-7-25" href = "#__codelineno-7-25" > < / a > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > permutationsI< / span > < span class = "p" > (< / span > < span class = "kt" > int< / span > < span class = "p" > []< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-7-26" name = "__codelineno-7-26" href = "#__codelineno-7-26" > < / a > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "p" > ();< / span >
< a id = "__codelineno-7-27" name = "__codelineno-7-27" href = "#__codelineno-7-27" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "p" > (),< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "kt" > bool< / span > < span class = "p" > [< / span > < span class = "n" > nums< / span > < span class = "p" > .< / span > < span class = "n" > Length< / span > < span class = "p" > ],< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-7-28" name = "__codelineno-7-28" href = "#__codelineno-7-28" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-7-29" name = "__codelineno-7-29" href = "#__codelineno-7-29" > < / a > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_i.swift< / span > < pre > < span > < / span > < code > < a id = "__codelineno-8-1" name = "__codelineno-8-1" href = "#__codelineno-8-1" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-8-2" name = "__codelineno-8-2" href = "#__codelineno-8-2" > < / a >
< a id = "__codelineno-8-3" name = "__codelineno-8-3" href = "#__codelineno-8-3" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > permutationsI< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_i.zig< / span > < pre > < span > < / span > < code > < a id = "__codelineno-9-1" name = "__codelineno-9-1" href = "#__codelineno-9-1" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-9-2" name = "__codelineno-9-2" href = "#__codelineno-9-2" > < / a >
< a id = "__codelineno-9-3" name = "__codelineno-9-3" href = "#__codelineno-9-3" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > permutationsI< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< / div >
@ -2026,17 +2088,24 @@
< a id = "__codelineno-10-11" name = "__codelineno-10-11" href = "#__codelineno-10-11" > < / a > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > choice< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-10-12" name = "__codelineno-10-12" href = "#__codelineno-10-12" > < / a > < span class = "w" > < / span > < span class = "c1" > // 剪枝:不允许重复选择元素 且 不允许重复选择相等元素< / span >
< a id = "__codelineno-10-13" name = "__codelineno-10-13" href = "#__codelineno-10-13" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > & & < / span > < span class = "w" > < / span > < span class = "o" > !< / span > < span class = "n" > duplicated< / span > < span class = "p" > .< / span > < span class = "na" > contains< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > ))< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-10-14" name = "__codelineno-10-14" href = "#__codelineno-10-14" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试< / span >
< a id = "__codelineno-10-14" name = "__codelineno-10-14" href = "#__codelineno-10-14" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试:做出选择,更新状态 < / span >
< a id = "__codelineno-10-15" name = "__codelineno-10-15" href = "#__codelineno-10-15" > < / a > < span class = "w" > < / span > < span class = "n" > duplicated< / span > < span class = "p" > .< / span > < span class = "na" > add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 记录选择过的元素值< / span >
< a id = "__codelineno-10-16" name = "__codelineno-10-16" href = "#__codelineno-10-16" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > true< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 做出选择< / span >
< a id = "__codelineno-10-17" name = "__codelineno-10-17" href = "#__codelineno-10-17" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 更新状态< / span >
< a id = "__codelineno-10-16" name = "__codelineno-10-16" href = "#__codelineno-10-16" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > true< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-10-17" name = "__codelineno-10-17" href = "#__codelineno-10-17" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span >
< a id = "__codelineno-10-18" name = "__codelineno-10-18" href = "#__codelineno-10-18" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-10-19" name = "__codelineno-10-19" href = "#__codelineno-10-19" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退< / span >
< a id = "__codelineno-10-20" name = "__codelineno-10-20" href = "#__codelineno-10-20" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > false< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 撤销选择< / span >
< a id = "__codelineno-10-21" name = "__codelineno-10-21" href = "#__codelineno-10-21" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > remove< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > size< / span > < span class = "p" > ()< / span > < span class = "w" > < / span > < span class = "o" > -< / span > < span class = "w" > < / span > < span class = "mi" > 1< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 恢复到之前的状态< / span >
< a id = "__codelineno-10-19" name = "__codelineno-10-19" href = "#__codelineno-10-19" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退:撤销选择,恢复到之前的状态 < / span >
< a id = "__codelineno-10-20" name = "__codelineno-10-20" href = "#__codelineno-10-20" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "o" > [< / span > < span class = "n" > i< / span > < span class = "o" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "kc" > false< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-10-21" name = "__codelineno-10-21" href = "#__codelineno-10-21" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > remove< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "na" > size< / span > < span class = "p" > ()< / span > < span class = "w" > < / span > < span class = "o" > -< / span > < span class = "w" > < / span > < span class = "mi" > 1< / span > < span class = "p" > );< / span >
< a id = "__codelineno-10-22" name = "__codelineno-10-22" href = "#__codelineno-10-22" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-10-23" name = "__codelineno-10-23" href = "#__codelineno-10-23" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-10-24" name = "__codelineno-10-24" href = "#__codelineno-10-24" > < / a > < span class = "p" > }< / span >
< a id = "__codelineno-10-25" name = "__codelineno-10-25" href = "#__codelineno-10-25" > < / a >
< a id = "__codelineno-10-26" name = "__codelineno-10-26" href = "#__codelineno-10-26" > < / a > < span class = "cm" > /* 全排列 II */< / span >
< a id = "__codelineno-10-27" name = "__codelineno-10-27" href = "#__codelineno-10-27" > < / a > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "nf" > permutationsII< / span > < span class = "p" > (< / span > < span class = "kt" > int< / span > < span class = "o" > []< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-10-28" name = "__codelineno-10-28" href = "#__codelineno-10-28" > < / a > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > ArrayList< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > > < / span > < span class = "p" > ();< / span >
< a id = "__codelineno-10-29" name = "__codelineno-10-29" href = "#__codelineno-10-29" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > ArrayList< / span > < span class = "o" > < < / span > < span class = "n" > Integer< / span > < span class = "o" > > < / span > < span class = "p" > (),< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "kt" > boolean< / span > < span class = "o" > [< / span > < span class = "n" > nums< / span > < span class = "p" > .< / span > < span class = "na" > length< / span > < span class = "o" > ]< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-10-30" name = "__codelineno-10-30" href = "#__codelineno-10-30" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-10-31" name = "__codelineno-10-31" href = "#__codelineno-10-31" > < / a > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
@ -2053,17 +2122,26 @@
< a id = "__codelineno-11-11" name = "__codelineno-11-11" href = "#__codelineno-11-11" > < / a > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > choice< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ];< / span >
< a id = "__codelineno-11-12" name = "__codelineno-11-12" href = "#__codelineno-11-12" > < / a > < span class = "w" > < / span > < span class = "c1" > // 剪枝:不允许重复选择元素 且 不允许重复选择相等元素< / span >
< a id = "__codelineno-11-13" name = "__codelineno-11-13" href = "#__codelineno-11-13" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > & & < / span > < span class = "w" > < / span > < span class = "n" > duplicated< / span > < span class = "p" > .< / span > < span class = "n" > find< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "o" > ==< / span > < span class = "w" > < / span > < span class = "n" > duplicated< / span > < span class = "p" > .< / span > < span class = "n" > end< / span > < span class = "p" > ())< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-11-14" name = "__codelineno-11-14" href = "#__codelineno-11-14" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试< / span >
< a id = "__codelineno-11-14" name = "__codelineno-11-14" href = "#__codelineno-11-14" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试:做出选择,更新状态 < / span >
< a id = "__codelineno-11-15" name = "__codelineno-11-15" href = "#__codelineno-11-15" > < / a > < span class = "w" > < / span > < span class = "n" > duplicated< / span > < span class = "p" > .< / span > < span class = "n" > emplace< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 记录选择过的元素值< / span >
< a id = "__codelineno-11-16" name = "__codelineno-11-16" href = "#__codelineno-11-16" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > true< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 做出选择< / span >
< a id = "__codelineno-11-17" name = "__codelineno-11-17" href = "#__codelineno-11-17" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > push_back< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 更新状态< / span >
< a id = "__codelineno-11-16" name = "__codelineno-11-16" href = "#__codelineno-11-16" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > true< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-11-17" name = "__codelineno-11-17" href = "#__codelineno-11-17" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > push_back< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span >
< a id = "__codelineno-11-18" name = "__codelineno-11-18" href = "#__codelineno-11-18" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-11-19" name = "__codelineno-11-19" href = "#__codelineno-11-19" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退< / span >
< a id = "__codelineno-11-20" name = "__codelineno-11-20" href = "#__codelineno-11-20" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > false< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "c1" > // 撤销选择< / span >
< a id = "__codelineno-11-21" name = "__codelineno-11-21" href = "#__codelineno-11-21" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > pop_back< / span > < span class = "p" > ();< / span > < span class = "w" > < / span > < span class = "c1" > // 恢复到之前的状态< / span >
< a id = "__codelineno-11-19" name = "__codelineno-11-19" href = "#__codelineno-11-19" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退:撤销选择,恢复到之前的状态 < / span >
< a id = "__codelineno-11-20" name = "__codelineno-11-20" href = "#__codelineno-11-20" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "nb" > false< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-11-21" name = "__codelineno-11-21" href = "#__codelineno-11-21" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > pop_back< / span > < span class = "p" > ();< / span >
< a id = "__codelineno-11-22" name = "__codelineno-11-22" href = "#__codelineno-11-22" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-11-23" name = "__codelineno-11-23" href = "#__codelineno-11-23" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-11-24" name = "__codelineno-11-24" href = "#__codelineno-11-24" > < / a > < span class = "p" > }< / span >
< a id = "__codelineno-11-25" name = "__codelineno-11-25" href = "#__codelineno-11-25" > < / a >
< a id = "__codelineno-11-26" name = "__codelineno-11-26" href = "#__codelineno-11-26" > < / a > < span class = "cm" > /* 全排列 II */< / span >
< a id = "__codelineno-11-27" name = "__codelineno-11-27" href = "#__codelineno-11-27" > < / a > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > permutationsII< / span > < span class = "p" > (< / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-11-28" name = "__codelineno-11-28" href = "#__codelineno-11-28" > < / a > < span class = "w" > < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-11-29" name = "__codelineno-11-29" href = "#__codelineno-11-29" > < / a > < span class = "w" > < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > bool< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > (< / span > < span class = "n" > nums< / span > < span class = "p" > .< / span > < span class = "n" > size< / span > < span class = "p" > (),< / span > < span class = "w" > < / span > < span class = "nb" > false< / span > < span class = "p" > );< / span >
< a id = "__codelineno-11-30" name = "__codelineno-11-30" href = "#__codelineno-11-30" > < / a > < span class = "w" > < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "n" > vector< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-11-31" name = "__codelineno-11-31" href = "#__codelineno-11-31" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-11-32" name = "__codelineno-11-32" href = "#__codelineno-11-32" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-11-33" name = "__codelineno-11-33" href = "#__codelineno-11-33" > < / a > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
@ -2080,42 +2158,90 @@
< a id = "__codelineno-12-11" name = "__codelineno-12-11" href = "#__codelineno-12-11" > < / a > < span class = "k" > for< / span > < span class = "n" > i< / span > < span class = "p" > ,< / span > < span class = "n" > choice< / span > < span class = "ow" > in< / span > < span class = "nb" > enumerate< / span > < span class = "p" > (< / span > < span class = "n" > choices< / span > < span class = "p" > ):< / span >
< a id = "__codelineno-12-12" name = "__codelineno-12-12" href = "#__codelineno-12-12" > < / a > < span class = "c1" > # 剪枝:不允许重复选择元素 且 不允许重复选择相等元素< / span >
< a id = "__codelineno-12-13" name = "__codelineno-12-13" href = "#__codelineno-12-13" > < / a > < span class = "k" > if< / span > < span class = "ow" > not< / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "ow" > and< / span > < span class = "n" > choice< / span > < span class = "ow" > not< / span > < span class = "ow" > in< / span > < span class = "n" > duplicated< / span > < span class = "p" > :< / span >
< a id = "__codelineno-12-14" name = "__codelineno-12-14" href = "#__codelineno-12-14" > < / a > < span class = "c1" > # 尝试< / span >
< a id = "__codelineno-12-14" name = "__codelineno-12-14" href = "#__codelineno-12-14" > < / a > < span class = "c1" > # 尝试:做出选择,更新状态 < / span >
< a id = "__codelineno-12-15" name = "__codelineno-12-15" href = "#__codelineno-12-15" > < / a > < span class = "n" > duplicated< / span > < span class = "o" > .< / span > < span class = "n" > add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > )< / span > < span class = "c1" > # 记录选择过的元素值< / span >
< a id = "__codelineno-12-16" name = "__codelineno-12-16" href = "#__codelineno-12-16" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > True< / span > < span class = "c1" > # 做出选择< / span >
< a id = "__codelineno-12-17" name = "__codelineno-12-17" href = "#__codelineno-12-17" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > append< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > )< / span > < span class = "c1" > # 更新状态< / span >
< a id = "__codelineno-12-16" name = "__codelineno-12-16" href = "#__codelineno-12-16" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > True< / span >
< a id = "__codelineno-12-17" name = "__codelineno-12-17" href = "#__codelineno-12-17" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > append< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > )< / span >
< a id = "__codelineno-12-18" name = "__codelineno-12-18" href = "#__codelineno-12-18" > < / a > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "n" > res< / span > < span class = "p" > )< / span >
< a id = "__codelineno-12-19" name = "__codelineno-12-19" href = "#__codelineno-12-19" > < / a > < span class = "c1" > # 回退< / span >
< a id = "__codelineno-12-20" name = "__codelineno-12-20" href = "#__codelineno-12-20" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > False< / span > < span class = "c1" > # 撤销选择< / span >
< a id = "__codelineno-12-21" name = "__codelineno-12-21" href = "#__codelineno-12-21" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > ()< / span > < span class = "c1" > # 恢复到之前的状态< / span >
< a id = "__codelineno-12-19" name = "__codelineno-12-19" href = "#__codelineno-12-19" > < / a > < span class = "c1" > # 回退:撤销选择,恢复到之前的状态< / span >
< a id = "__codelineno-12-20" name = "__codelineno-12-20" href = "#__codelineno-12-20" > < / a > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "o" > =< / span > < span class = "kc" > False< / span >
< a id = "__codelineno-12-21" name = "__codelineno-12-21" href = "#__codelineno-12-21" > < / a > < span class = "n" > state< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > ()< / span >
< a id = "__codelineno-12-22" name = "__codelineno-12-22" href = "#__codelineno-12-22" > < / a >
< a id = "__codelineno-12-23" name = "__codelineno-12-23" href = "#__codelineno-12-23" > < / a > < span class = "k" > def< / span > < span class = "nf" > permutations_ii< / span > < span class = "p" > (< / span > < span class = "n" > nums< / span > < span class = "p" > :< / span > < span class = "nb" > list< / span > < span class = "p" > [< / span > < span class = "nb" > int< / span > < span class = "p" > ])< / span > < span class = "o" > -> < / span > < span class = "nb" > list< / span > < span class = "p" > [< / span > < span class = "nb" > list< / span > < span class = "p" > [< / span > < span class = "nb" > int< / span > < span class = "p" > ]]:< / span >
< a id = "__codelineno-12-24" name = "__codelineno-12-24" href = "#__codelineno-12-24" > < / a > < span class = "w" > < / span > < span class = "sd" > " " " 全排列 II" " " < / span >
< a id = "__codelineno-12-25" name = "__codelineno-12-25" href = "#__codelineno-12-25" > < / a > < span class = "n" > res< / span > < span class = "o" > =< / span > < span class = "p" > []< / span >
< a id = "__codelineno-12-26" name = "__codelineno-12-26" href = "#__codelineno-12-26" > < / a > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "o" > =< / span > < span class = "p" > [],< / span > < span class = "n" > choices< / span > < span class = "o" > =< / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "n" > selected< / span > < span class = "o" > =< / span > < span class = "p" > [< / span > < span class = "kc" > False< / span > < span class = "p" > ]< / span > < span class = "o" > *< / span > < span class = "nb" > len< / span > < span class = "p" > (< / span > < span class = "n" > nums< / span > < span class = "p" > ),< / span > < span class = "n" > res< / span > < span class = "o" > =< / span > < span class = "n" > res< / span > < span class = "p" > )< / span >
< a id = "__codelineno-12-27" name = "__codelineno-12-27" href = "#__codelineno-12-27" > < / a > < span class = "k" > return< / span > < span class = "n" > res< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_ii.go< / span > < pre > < span > < / span > < code > < a id = "__codelineno-13-1" name = "__codelineno-13-1" href = "#__codelineno-13-1" > < / a > < span class = "p" > [< / span > < span class = "nx" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-13-2" name = "__codelineno-13-2" href = "#__codelineno-13-2" > < / a >
< a id = "__codelineno-13-3" name = "__codelineno-13-3" href = "#__codelineno-13-3" > < / a > < span class = "p" > [< / span > < span class = "nx" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > permutationsII< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_ii.js< / span > < pre > < span > < / span > < code > < a id = "__codelineno-14-1" name = "__codelineno-14-1" href = "#__codelineno-14-1" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-14-2" name = "__codelineno-14-2" href = "#__codelineno-14-2" > < / a >
< a id = "__codelineno-14-3" name = "__codelineno-14-3" href = "#__codelineno-14-3" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > permutationsII< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_ii.ts< / span > < pre > < span > < / span > < code > < a id = "__codelineno-15-1" name = "__codelineno-15-1" href = "#__codelineno-15-1" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-15-2" name = "__codelineno-15-2" href = "#__codelineno-15-2" > < / a >
< a id = "__codelineno-15-3" name = "__codelineno-15-3" href = "#__codelineno-15-3" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "nx" > func< / span > < span class = "p" > ]{< / span > < span class = "nx" > permutationsII< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_ii.c< / span > < pre > < span > < / span > < code > < a id = "__codelineno-16-1" name = "__codelineno-16-1" href = "#__codelineno-16-1" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-16-2" name = "__codelineno-16-2" href = "#__codelineno-16-2" > < / a >
< a id = "__codelineno-16-3" name = "__codelineno-16-3" href = "#__codelineno-16-3" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > permutationsII< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_ii.cs< / span > < pre > < span > < / span > < code > < a id = "__codelineno-17-1" name = "__codelineno-17-1" href = "#__codelineno-17-1" > < / a > < span class = "na" > [class]< / span > < span class = "p" > {< / span > < span class = "n" > permutations_ii< / span > < span class = "p" > }< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< div class = "highlight" > < span class = "filename" > permutations_ii.cs< / span > < pre > < span > < / span > < code > < a id = "__codelineno-17-1" name = "__codelineno-17-1" href = "#__codelineno-17-1" > < / a > < span class = "cm" > /* 回溯算法:全排列 II */< / span >
< a id = "__codelineno-17-2" name = "__codelineno-17-2" href = "#__codelineno-17-2" > < / a > < span class = "k" > void< / span > < span class = "w" > < / span > < span class = "nf" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "p" > []< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "kt" > bool< / span > < span class = "p" > []< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-17-3" name = "__codelineno-17-3" href = "#__codelineno-17-3" > < / a > < span class = "w" > < / span > < span class = "c1" > // 当状态长度等于元素数量时,记录解< / span >
< a id = "__codelineno-17-4" name = "__codelineno-17-4" href = "#__codelineno-17-4" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > Count< / span > < span class = "w" > < / span > < span class = "o" > ==< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > .< / span > < span class = "n" > Length< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-17-5" name = "__codelineno-17-5" href = "#__codelineno-17-5" > < / a > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > .< / span > < span class = "n" > Add< / span > < span class = "p" > (< / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ));< / span >
< a id = "__codelineno-17-6" name = "__codelineno-17-6" href = "#__codelineno-17-6" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-17-7" name = "__codelineno-17-7" href = "#__codelineno-17-7" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-17-8" name = "__codelineno-17-8" href = "#__codelineno-17-8" > < / a > < span class = "w" > < / span > < span class = "c1" > // 遍历所有选择< / span >
< a id = "__codelineno-17-9" name = "__codelineno-17-9" href = "#__codelineno-17-9" > < / a > < span class = "w" > < / span > < span class = "n" > ISet< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "w" > < / span > < span class = "n" > duplicated< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > HashSet< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "p" > ();< / span >
< a id = "__codelineno-17-10" name = "__codelineno-17-10" href = "#__codelineno-17-10" > < / a > < span class = "w" > < / span > < span class = "k" > for< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > i< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "m" > 0< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "n" > i< / span > < span class = "w" > < / span > < span class = "o" > < < / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > .< / span > < span class = "n" > Length< / span > < span class = "p" > ;< / span > < span class = "w" > < / span > < span class = "n" > i< / span > < span class = "o" > ++< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-17-11" name = "__codelineno-17-11" href = "#__codelineno-17-11" > < / a > < span class = "w" > < / span > < span class = "kt" > int< / span > < span class = "w" > < / span > < span class = "n" > choice< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ];< / span >
< a id = "__codelineno-17-12" name = "__codelineno-17-12" href = "#__codelineno-17-12" > < / a > < span class = "w" > < / span > < span class = "c1" > // 剪枝:不允许重复选择元素 且 不允许重复选择相等元素< / span >
< a id = "__codelineno-17-13" name = "__codelineno-17-13" href = "#__codelineno-17-13" > < / a > < span class = "w" > < / span > < span class = "k" > if< / span > < span class = "w" > < / span > < span class = "p" > (< / span > < span class = "o" > !< / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > & & < / span > < span class = "w" > < / span > < span class = "o" > !< / span > < span class = "n" > duplicated< / span > < span class = "p" > .< / span > < span class = "n" > Contains< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > ))< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-17-14" name = "__codelineno-17-14" href = "#__codelineno-17-14" > < / a > < span class = "w" > < / span > < span class = "c1" > // 尝试:做出选择,更新状态< / span >
< a id = "__codelineno-17-15" name = "__codelineno-17-15" href = "#__codelineno-17-15" > < / a > < span class = "w" > < / span > < span class = "n" > duplicated< / span > < span class = "p" > .< / span > < span class = "n" > Add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span > < span class = "w" > < / span > < span class = "c1" > // 记录选择过的元素值< / span >
< a id = "__codelineno-17-16" name = "__codelineno-17-16" href = "#__codelineno-17-16" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > true< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-17-17" name = "__codelineno-17-17" href = "#__codelineno-17-17" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > Add< / span > < span class = "p" > (< / span > < span class = "n" > choice< / span > < span class = "p" > );< / span >
< a id = "__codelineno-17-18" name = "__codelineno-17-18" href = "#__codelineno-17-18" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > choices< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-17-19" name = "__codelineno-17-19" href = "#__codelineno-17-19" > < / a > < span class = "w" > < / span > < span class = "c1" > // 回退:撤销选择,恢复到之前的状态< / span >
< a id = "__codelineno-17-20" name = "__codelineno-17-20" href = "#__codelineno-17-20" > < / a > < span class = "w" > < / span > < span class = "n" > selected< / span > < span class = "p" > [< / span > < span class = "n" > i< / span > < span class = "p" > ]< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > false< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-17-21" name = "__codelineno-17-21" href = "#__codelineno-17-21" > < / a > < span class = "w" > < / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > RemoveAt< / span > < span class = "p" > (< / span > < span class = "n" > state< / span > < span class = "p" > .< / span > < span class = "n" > Count< / span > < span class = "w" > < / span > < span class = "o" > -< / span > < span class = "w" > < / span > < span class = "m" > 1< / span > < span class = "p" > );< / span >
< a id = "__codelineno-17-22" name = "__codelineno-17-22" href = "#__codelineno-17-22" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-17-23" name = "__codelineno-17-23" href = "#__codelineno-17-23" > < / a > < span class = "w" > < / span > < span class = "p" > }< / span >
< a id = "__codelineno-17-24" name = "__codelineno-17-24" href = "#__codelineno-17-24" > < / a > < span class = "p" > }< / span >
< a id = "__codelineno-17-25" name = "__codelineno-17-25" href = "#__codelineno-17-25" > < / a >
< a id = "__codelineno-17-26" name = "__codelineno-17-26" href = "#__codelineno-17-26" > < / a > < span class = "cm" > /* 全排列 II */< / span >
< a id = "__codelineno-17-27" name = "__codelineno-17-27" href = "#__codelineno-17-27" > < / a > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > permutationsII< / span > < span class = "p" > (< / span > < span class = "kt" > int< / span > < span class = "p" > []< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > )< / span > < span class = "w" > < / span > < span class = "p" > {< / span >
< a id = "__codelineno-17-28" name = "__codelineno-17-28" href = "#__codelineno-17-28" > < / a > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "w" > < / span > < span class = "o" > =< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > > < / span > < span class = "p" > ();< / span >
< a id = "__codelineno-17-29" name = "__codelineno-17-29" href = "#__codelineno-17-29" > < / a > < span class = "w" > < / span > < span class = "n" > backtrack< / span > < span class = "p" > (< / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "n" > List< / span > < span class = "o" > < < / span > < span class = "kt" > int< / span > < span class = "o" > > < / span > < span class = "p" > (),< / span > < span class = "w" > < / span > < span class = "n" > nums< / span > < span class = "p" > ,< / span > < span class = "w" > < / span > < span class = "k" > new< / span > < span class = "w" > < / span > < span class = "kt" > bool< / span > < span class = "p" > [< / span > < span class = "n" > nums< / span > < span class = "p" > .< / span > < span class = "n" > Length< / span > < span class = "p" > ],< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > );< / span >
< a id = "__codelineno-17-30" name = "__codelineno-17-30" href = "#__codelineno-17-30" > < / a > < span class = "w" > < / span > < span class = "k" > return< / span > < span class = "w" > < / span > < span class = "n" > res< / span > < span class = "p" > ;< / span >
< a id = "__codelineno-17-31" name = "__codelineno-17-31" href = "#__codelineno-17-31" > < / a > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_ii.swift< / span > < pre > < span > < / span > < code > < a id = "__codelineno-18-1" name = "__codelineno-18-1" href = "#__codelineno-18-1" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-18-2" name = "__codelineno-18-2" href = "#__codelineno-18-2" > < / a >
< a id = "__codelineno-18-3" name = "__codelineno-18-3" href = "#__codelineno-18-3" > < / a > < span class = "p" > [< / span > < span class = "kd" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "kd" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > permutationsII< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< div class = "tabbed-block" >
< div class = "highlight" > < span class = "filename" > permutations_ii.zig< / span > < pre > < span > < / span > < code > < a id = "__codelineno-19-1" name = "__codelineno-19-1" href = "#__codelineno-19-1" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > backtrack< / span > < span class = "p" > }< / span >
< a id = "__codelineno-19-2" name = "__codelineno-19-2" href = "#__codelineno-19-2" > < / a >
< a id = "__codelineno-19-3" name = "__codelineno-19-3" href = "#__codelineno-19-3" > < / a > < span class = "p" > [< / span > < span class = "n" > class< / span > < span class = "p" > ]{}< / span > < span class = "o" > -< / span > < span class = "p" > [< / span > < span class = "n" > func< / span > < span class = "p" > ]{< / span > < span class = "n" > permutationsII< / span > < span class = "p" > }< / span >
< / code > < / pre > < / div >
< / div >
< / div >