Leetcode-Permutation ll(深搜)
来源:互联网 发布:罗技g303编程 编辑:程序博客网 时间:2024/06/08 18:36
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], [2,1,1]]
class Solution {public: vector<vector<int>> ans; vector<int> tmp; bool canSwap(int i, int j, vector<int>& nums) { for(int k=i; k<j; k++) if(nums[k] == nums[j]) return false; return true; } void dfs(int depth, vector<int>& nums) { if(depth >= nums.size()-1) { tmp.clear(); for(int i=0; i<nums.size(); i++) tmp.push_back(nums[i]); ans.push_back(tmp); return; } for(int i=depth; i<nums.size(); i++) { if(canSwap(depth, i, nums)) { swap(nums[depth], nums[i]); dfs(depth+1, nums); swap(nums[depth], nums[i]); } } } vector<vector<int>> permuteUnique(vector<int>& nums) { dfs(0, nums); return ans; }};类似于Permutation,只是多加了一个判断条件
阅读全文
0 0
- Leetcode-Permutation ll(深搜)
- Leetcode-Combination Sum ll(深搜)
- LeetCode(31) Next Permutation
- LeetCode(60) Permutation Sequence
- leetcode-全排列(permutation)
- LeetCode (31)Next Permutation
- LeetCode Permutation
- [LeetCode] Permutation
- LeetCode-Permutation
- Leetcode--Permutation
- Permutation--LeetCode
- leetcode permutation
- *LeetCode-Permutation
- LeetCode之Permutation、Permutation II
- leetcode -- Permutation & Permutation II--重点
- LeetCode 题解(4):Next Permutation
- LeetCode | Next Permutation(下一个排列)
- LeetCode OJ 之 Permutation Sequence (排列组合)
- python3 urllib.parse.urljoin()用法
- 制作Wi-Fi Ducky远程HID攻击设备
- CK小说程序 2.0 一款超棒的小说管理网站
- Spark调优
- fork出的子进程和父进程
- Leetcode-Permutation ll(深搜)
- A
- SAS不能读取复杂的csv文件怎么办?
- Java中的位运算符(操作数只能是整型和字符型数据)
- 大数乘法
- MySQL中字符集 utf8mb4与utf8的区别
- 8月7日云栖精选夜读:五分钟读懂SIGIR 2017前沿技术研究成果
- 解决android studio logcat 只显示部分数据
- 6377:生日相同 2.0(3.1数据结构之结构)