记录题目:
- 复原 IP 地址
- 子集 II
- 递增子序列
- 全排列
- 全排列 II
给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式。
有效 IP 地址由四个整数(每个整数位于 0 到 255 之间,且不含前导 0)组成,整数之间用 . 分隔。
| 12
 3
 4
 5
 6
 7
 8
 
 | for(let j = i; j < s.length; j++) {const str = s.slice(i, j + 1);
 if(str.length > 3 || +str > 255) break;
 if(str.length > 1 && str[0] === "0") break;
 path.push(str);
 backtracking(j + 1);
 path.pop()
 }
 
 | 
给定一个可能包含重复元素的整数数组 nums,
返回该数组所有可能的子集(幂集)。
解集不能包含重复的子集。
| 12
 3
 4
 5
 6
 
 | for (let i = startIndex; i < len; i++) {if (i > startIndex && nums[i] === nums[i - 1]) continue;
 path.push(nums[i]);
 backtracking(i + 1);
 path.pop();
 }
 
 | 
给定一个整型数组,找到所有该数组的递增子序列,
递增子序列的长度至少是 2。
数组中的整数范围是 [-100,100],可能包含重复数字。
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 
 | let uset = []for(let i = startIndex; i < nums.length; i++) {
 if((path.length > 0 && nums[i] < path[path.length - 1]) || uset[nums[i] + 100]) {
 continue
 }
 uset[nums[i] + 100] = true
 path.push(nums[i])
 backtracing(i + 1)
 path.pop()
 }
 
 | 
给定一个不含重复数字的序列,返回其所有可能的全排列。
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 
 | var permute = function (nums) {const res = [], path = [], len = nums.length, used = [];
 const backtracking = () => {
 if (path.length === len) res.push(path.slice(0));
 for (let i = 0; i < len; i++) {
 if (used[i]) continue;
 path.push(nums[i]);
 used[i] = 1;
 backtracking();
 path.pop();
 used[i] = 0;
 }
 }
 backtracking();
 return res;
 };
 
 | 
给定一个可包含重复数字的序列,返回其所有不重复的全排列。
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 
 | for (let i = 0; i < nums.length; i++) {if ((i > 0 && nums[i] === nums[i - 1] && !used[i - 1]) || used[i]) {
 continue;
 }
 used[i] = true;
 path.push(nums[i]);
 backtracing(used);
 path.pop();
 used[i] = false;
 }
 
 |