题目链接

Permutations II - LeetCode

注意点

  • 不确定有几种排列

解法

解法一:因为有重复的数字所以排列的个数不确定几个,一直生成新的排列直到和原始的数列相同为止

class Solution {
public:
vector<int> nextPermutation(vector<int> nums) {
int n = nums.size(),i = n-2,j = n-1;
while(i >= 0 && nums[i] >= nums[i+1]) i--;
if(i >= 0)
{
while(nums[j] <= nums[i]) j--;
swap(nums[i],nums[j]);
}
reverse(nums.begin()+i+1,nums.end());
return nums;
}
vector<vector<int>> permuteUnique(vector<int>& nums) {
vector<vector<int>> ret;
ret.push_back(nums);
vector<int> temp = nextPermutation(nums);
while(temp != nums)
{
ret.push_back(temp);
temp = nextPermutation(temp);
}
return ret;
}
};

小结

Permutations II - LeetCode的更多相关文章

  1. Permutations II ——LeetCode

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

  2. Permutations II leetcode java

    题目: Given a collection of numbers that might contain duplicates, return all possible unique permutat ...

  3. leetcode Permutations II 无重全排列

    作者:jostree  转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...

  4. [Leetcode][Python]47: Permutations II

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 47: Permutations IIhttps://oj.leetcode. ...

  5. LeetCode解题报告—— Permutations & Permutations II & Rotate Image

    1. Permutations Given a collection of distinct numbers, return all possible permutations. For exampl ...

  6. Leetcode之回溯法专题-47. 全排列 II(Permutations II)

    Leetcode之回溯法专题-47. 全排列 II(Permutations II) 给定一个可包含重复数字的序列,返回所有不重复的全排列. 示例: 输入: [1,1,2] 输出: [ [1,1,2] ...

  7. 【leetcode】Permutations II

    Permutations II Given a collection of numbers that might contain duplicates, return all possible uni ...

  8. LeetCode:Permutations, Permutations II(求全排列)

    Permutations Given a collection of numbers, return all possible permutations. For example, [1,2,3] h ...

  9. leetcode总结:permutations, permutations II, next permutation, permutation sequence

    Next Permutation: Implement next permutation, which rearranges numbers into the lexicographically ne ...

随机推荐

  1. Python浮点算术:争议和限制

    浮点数在计算机硬件中表示为以 2 为基数(二进制)的小数.举例而言,十进制的小数 0.125 等于 1/10 + 2/100 + 5/1000 ,同理,二进制的小数 0.001 等于0/2 + 0/4 ...

  2. Oracle扩展包(pipe,alert,job,scheduler)

    --定义包中函数的纯度级别 create or replace package purityTest is type dept_typ is table of dept%rowtype index b ...

  3. Netty源码分析第5章(ByteBuf)---->第9节: ByteBuf回收

    Netty源码分析第五章: ByteBuf 第九节: ByteBuf回收 之前的章节我们提到过, 堆外内存是不受jvm垃圾回收机制控制的, 所以我们分配一块堆外内存进行ByteBuf操作时, 使用完毕 ...

  4. 一种利用ADO连接池操作MySQL的解决方案(VC++)

    VC++连接MySQL数据库 常用的方式有三种:ADO.mysql++,mysql API ; 本文只讲述ADO的连接方式. 为什么要使用连接池? 对于简单的数据库应用,完全可以先创建一个常连接(此连 ...

  5. Redis勒索事件爆发,如何避免从删库到跑路?

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯云数据库 TencentDB发表于云+社区专栏 9月10日下午,又一起规模化利用Redis未授权访问漏洞攻击数据库的事件发生,此次 ...

  6. XSS工具

    1.BEEF KALI中启动BEEFXSS PAYLOAD为 <script src=”http://攻击机IP:3000/hook.js”></script> 将攻击代码插入 ...

  7. Burp Suite pro 抓包工具配置

    下载地址: 链接:https://pan.baidu.com/s/1WyuAlJSWZ3HyyEQlpiH3cA 提取码:6l38 破解相关请查看解压文件链接 1.firefox代理设置: burp ...

  8. Java里字符串split方法

    Java中的split方法以"."切割字符串时,需要转义 String str[] = s.split("\\.");

  9. JAVA实验报告三:敏捷开发与XP实践

    实验内容 1. XP基础 2. XP核心实践 3. 相关工具 实验步骤 (一)敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法应用到软件的开发.运营和维护上的过程.软件工程包括下列领域:软件需 ...

  10. dazhewang数据库初设计

    mysql> use dazhe; Database changed mysql> create table shops(id int primary key auto_increment ...