[Leetcode 78/90] Subsets I/II

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

做个小补充:在subset II 中的15:10 时,其实要先吧nums[ ] 数组排序,才好判断任意相邻的重复数值。在代码的line 5 有具体实现。谢谢原作者的精彩分析!

jamesqiu
Автор

If we choose to sort the nums array before passing it into helper function, we can actually create a hashset for the res at the beginning and leave the helper almost remain unchanged. Of course, we still need to convert the res into the list of list format but it will simplify the logic of the program a little bit.

xueshisu
Автор

他说 curr.remove(curr.size()-1) 才是不选择的意思. 虽然代码一样, 但思路完全就反了

sidazhong
Автор

Subsets II 14:40 -- 16:13 The most important part that solved my confusion. Also, you don't need to use a boolean to record if an integer is taken or not. You can just write : if ( i > currtdx && nums[ i ] == nums [i - 1]) return; This will remove the situation that causes the duplicates.

vvwu
join shbcf.ru