题目描述

给出一组可能包含重复项的数字,返回该组数字的所有排列
例如;
[1,1,2]的排列如下:
[1,1,2],[1,2,1], [2,1,1].

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

For example,
[1,1,2]have the following unique permutations:
[1,1,2],[1,2,1], and[2,1,1].

class Solution {
    int array[19]={0};
    void permutation(vector<vector<int>> &ans ,vector<int> &num,int k,int n){
        if (k==n)
            ans.push_back(num);
        else
        {
            for (int i=0;i<19;i++){
                if (array[i]>0)
                {
                    array[i]--;
                    num[k]=i-9;
                    permutation(ans, num,  k+1,  n);
                    array[i]++;
                }
            }
        }
    }
public:
    vector<vector<int> > permuteUnique(vector<int> &num) {
        for (int i=0;i<num.size();i++){
            array[num[i]+9]++;
        }
        vector<vector<int>> ans;
        permutation(ans, num, 0, num.size());
        return ans;
    }
};

最新文章

  1. asp.net配置web.config支持jQuery.Uploadify插件上传大文件
  2. jprofiler_监控远程linux服务器的tomcat进程(实践)
  3. 加载信息,先从数据库取出5条实现分页,鼠标向上滑动触发Ajax再加载5条,达到异步刷新,优化加载。。。
  4. Python开发【第十一篇】:JavaScript
  5. Python验证Url地址的正则表达式
  6. java读取文件批量插入记录
  7. 面试整理之DOM事件阶段
  8. Hark的数据结构与算法练习之简单选择排序
  9. centos安装memcache与telnet
  10. The architecture of LTE network.
  11. Object c中的alloc和init问题
  12. Android获取当前时间与星期几
  13. Ionic android 底部tabs
  14. 深入理解JAVA序列化
  15. eclipse安装及配置pydev
  16. C++的字符串格式化库
  17. C#导出EXCEL,并生成charts表
  18. WPF INotifyPropertyChanged
  19. Python学习:16.Python面对对象(三、反射,构造方法,静态字段,静态方法)
  20. FPGA基础知识,应用,ASIC、ASSP区别(四)

热门文章

  1. 《C++primerplus》第7章练习题
  2. js 正则表达式 判断val是不是整数
  3. 如何部署MongoDB并开启远程访问Docker版
  4. Linux中断驱动程序
  5. 2020已经过去五分之四了,你确定还不来了解一下JS的rAF?
  6. canal快速启动
  7. go 实现websocket推送
  8. go 结构体与方法
  9. jmeter环境变量配置
  10. 【机器学习 Azure Machine Learning】使用Aure虚拟机搭建Jupyter notebook环境,为Machine Learning做准备(Ubuntu 18.04,Linux)