LeetCode--078--子集(python)】的更多相关文章

LeetCode:子集 II[90] 题目描述 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ [2], [1], [1,2,2], [2,2], [1,2], [] ] 题目分析 1.可能包含重复元素的整形数组,返回该数组的所有子集,但结果不能包含重复. 这句话的意思是结果集中的每一个元素都是独一无二的,如果我们用暴力递归的话,就会出现很多重复元素,比如{1,2}就会出现多次,我们可能…
给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集).输入: nums = [1,2,3]输出:[ [3],  [1],  [2],  [1,2,3],  [1,3],  [2,3],  [1,2],  []] class Solution: #回溯法 def subsets(self, nums): if not nums: return [] res = [] n = len(nums) def helper(idx, temp_list): res.append(te…
题目来源 https://leetcode.com/problems/subsets/ Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. 题意分析 Input: :type nums:…
题目来源 https://leetcode.com/problems/subsets-ii/ Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate su…
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" is a palindrome."race a car"…
题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [], [,4], [6,,7], [4,,8,3] ] The min…
题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. 题意分析 Input:integer Output:kth row of the Pascal's triangle Conditions:只返回第n行 题目思路 同118,不…
题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题意分析 Input:integer Output:帕斯卡三角 Conditions:帕斯卡三…
题目来源 https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If th…
题目来源 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Given a binary tree, flatten it to a linked list in-place. 题意分析 Input: binary tree Output: flattened tree Conditions:将一个二叉树压平为一个flatten 树,也就是一条斜线 题目思路 先将左右子树压平,然后将左子树嵌入到本节点与右子树之间.…