博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Subsets II
阅读量:4106 次
发布时间:2019-05-25

本文共 670 字,大约阅读时间需要 2 分钟。

题目:

解答:

在Subsets的基础上,加一个结果中是否存在该元素的判断。

代码:

class Solution {  public:	  vector
> subsetsWithDup(vector
&S) { vector
> res; vector
temp; int n = S.size(); if (n == 0) return res; sort(S.begin(), S.end()); search(0, n, res, temp, S); return res; } void search(int k, int n, vector
> &res, vector
&temp, vector
&S) { if (k == n) { if (find(res.begin(), res.end(), temp) == res.end()) res.push_back(temp); return; } temp.push_back(S[k]); search(k + 1, n, res, temp, S); temp.pop_back(); search(k + 1, n, res, temp, S); } };

转载地址:http://kytsi.baihongyu.com/

你可能感兴趣的文章
Remove Element--原地移除重复元素
查看>>
Remove Duplicates from Sorted Array--从有序数组中移除重复元素
查看>>
Count and Say
查看>>
Gas Station
查看>>
Palindrome Partitioning --回文切割 深搜(重重)
查看>>
Valid Palindrome 简单的回文判断
查看>>
Pascal's Triangle -- 生成杨辉三角
查看>>
Pascal's Triangle II 生成杨辉三角中的某行
查看>>
Minimum Depth of Binary Tree -- 二叉树的最小深度 DFS 加剪枝
查看>>
Climbing Stairs 爬楼梯方法 动态规划
查看>>
Merge Two Sorted Lists 合并两个有序链表
查看>>
pow(x,n) 为什么错这么多次
查看>>
Jump Game 动态规划
查看>>
Binary Tree Maximum Path Sum 自底向上求解(重重重重)
查看>>
Subsets 深搜
查看>>
Subsets II
查看>>
Edit Distance 字符串距离(重重)
查看>>
Gray Code 格雷码
查看>>
对话周鸿袆:从程序员创业谈起
查看>>
web.py 0.3 新手指南 - 如何用Gmail发送邮件
查看>>