魔术索引
思路:
直接代码
function findMagicIndex(nums) { let i = 0 if(!nums.length){ return -1 } else{ while(i <= nums.length && i !== nums[i]){ i ++ } let min = i > nums.length ? -1 : i return min } }
幂集
标签:11,arr,return,nums,金典,dfs,---,length,res From: https://www.cnblogs.com/dgqp/p/17338332.html思路:
使用递归的思路进行求解,
代码:
/** * @param {number[]} nums * @return {number[][]} */ var subsets = function(nums) { let res = [] dfs([], 0) return res function dfs(arr, index){ res.push([...arr]) for(let i = index; i < nums.length; i++){ arr.push(nums[i]) dfs(arr, i + 1) arr.pop() } } };