原文链接: https://leetcode-cn.com/problems/count-number-of-maximum-bitwise-or-subsets 英文原文Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise …
标签详情
回溯 分类
原文链接: https://leetcode-cn.com/problems/next-greater-numerically-balanced-number 英文原文An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x. Given an integer n, return the smallest…
原文链接: https://leetcode-cn.com/problems/maximum-path-quality-of-a-graph 英文原文There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the ith node. Yo…
原文链接: https://leetcode-cn.com/problems/power-set-lcci 英文原文Write a method to return all subsets of a set. The elements in a set are pairwise distinct. Note: The result set should not contain duplicated subsets. Example: Input: nums = [1,2,3] Output: […
原文链接: https://leetcode-cn.com/problems/bracket-lcci 英文原文Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n pairs of parentheses. Note: The result set should not contain duplicated subsets. For example, give…
原文链接: https://leetcode-cn.com/problems/eight-queens-lcci 英文原文Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals…
原文链接: https://leetcode-cn.com/problems/permutation-i-lcci 英文原文Write a method to compute all permutations of a string of unique characters. Example1: Input: S = "qwe" Output: ["qwe", "qew", "wqe", "weq", "ewq", "eqw"] Example2: Input: S = "ab" Output:…
原文链接: https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof 中文题目给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中,返回 true ;否则,返回 false 。 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。 例如,在下面的 3×4 的矩阵中包含单词 "ABCCED…
原文链接: https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof 中文题目输入一个字符串,打印出该字符串中字符的所有排列。 你可以以任意顺序返回这个字符串数组,但里面不能有重复元素。 示例: 输入:s = "abc" 输出:["abc","acb","bac","bca","cab","cba"] 限制: 1 <= s 的长度 <= 8 通过代码 高赞题解解题思路:对于一个长度为 $n$ 的字符串(假设字符互不重复),其排列方案…
原文链接: https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof 中文题目给你二叉树的根节点 root 和一个整数目标和 targetSum ,找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。 叶子节点 是指没有子节点的节点。 示例 1: 输入:root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22 输出…
原文链接: https://leetcode-cn.com/problems/permutation-ii-lcci 英文原文Write a method to compute all permutations of a string whose characters are not necessarily unique. The list of permutations should not have duplicates. Example1: Input: S = "qqe" Output:…
原文链接: https://leetcode-cn.com/problems/robot-in-a-grid-lcci 英文原文Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can only move in two directions, right and down, but certain cells are "off limits" such tha…
原文链接: https://leetcode-cn.com/problems/pattern-matching-lcci 英文原文You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matche…
原文链接: https://leetcode-cn.com/problems/word-transformer-lcci 英文原文Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step…
原文链接: https://leetcode-cn.com/problems/word-rectangle-lcci 英文原文Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms …
原文链接: https://leetcode-cn.com/problems/Ygoe9J 中文题目给定一个无重复元素的正整数数组 candidates 和一个正整数 target ,找出 candidates 中所有可以使数字和为目标数 target 的唯一组合。 candidates 中的数字可以无限制重复被选取。如果至少一个所选数字数量不同,则两种组合是唯一的。 对于给定的输入,保证和为 target 的唯一组合数少于 150 个。 示例 1: 输入: candidates = [2,3,…
原文链接: https://leetcode-cn.com/problems/4sjJUc 中文题目给定一个可能有重复数字的整数数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用一次,解集不能包含重复的组合。 示例 1: 输入: candidates = [10,1,2,7,6,1,5], target = 8, 输出: [ [1,1,6], [1,2,5], …
原文链接: https://leetcode-cn.com/problems/VvJkup 中文题目给定一个不含重复数字的整数数组 nums ,返回其 所有可能的全排列 。可以 按任意顺序 返回答案。 示例 1: 输入:nums = [1,2,3] 输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 示例 2: 输入:nums = [0,1] 输出:[[0,1],[1,0]] 示例 3: 输入:nums = [1] 输出:[[1]] 提示: …
原文链接: https://leetcode-cn.com/problems/IDBivT 中文题目正整数 n 代表生成括号的对数,请设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。 示例 1: 输入:n = 3 输出:["((()))","(()())","(())()","()(())","()()()"] 示例 2: 输入:n = 1 输出:["()"] 提示: 1 <= n <= 8 注意:本题与主站 22 题相同: https://leetcode-cn.com/probl…
原文链接: https://leetcode-cn.com/problems/M99OJA 中文题目给定一个字符串 s ,请将 s 分割成一些子串,使每个子串都是 回文串 ,返回 s 所有可能的分割方案。 回文串 是正着读和反着读都一样的字符串。 示例 1: 输入:s = "google" 输出:[["g","o","o","g","l","e"],["g","oo","g","l","e"],["goog","l","e"]] 示例 2: 输入:s = "aab" 输出:[["a","a","…
原文链接: https://leetcode-cn.com/problems/0on3uN 中文题目给定一个只包含数字的字符串 s ,用以表示一个 IP 地址,返回所有可能从 s 获得的 有效 IP 地址 。你可以按任何顺序返回答案。 有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用 '.' 分隔。 例如:"0.1.2.201" 和 "192.168.1.1" 是 有效 IP 地址,但是 "0.011.255.245"、"192.168.…
原文链接: https://leetcode-cn.com/problems/YaVDxD 中文题目给定一个正整数数组 nums 和一个整数 target 。 向数组中的每个整数前添加 '+' 或 '-' ,然后串联起所有整数,可以构造一个 表达式 : 例如,nums = [2, 1] ,可以在 2 之前添加 '+' ,在 1 之前添加 '-' ,然后串联起来得到表达式 "+2-1" 。 返回可以通过上述方法构造的、运算结果等于 target 的不同 表达式 的数目。 示例 1: 输入:nums…
原文链接: https://leetcode-cn.com/problems/bP4bmD 中文题目给定一个有 n 个节点的有向无环图,用二维数组 graph 表示,请找到所有从 0 到 n-1 的路径并输出(不要求按顺序)。 graph 的第 i 个数组中的单元都表示有向图中 i 号节点所能到达的下一些结点(译者注:有向图是有方向的,即规定了 a→b 你就不能从 b→a ),若为空,就是没有下一个节点了。 示例 1: 输入:graph = [[1,2],[3],[3],[]…
原文链接: https://leetcode-cn.com/problems/TVdhkn 中文题目给定一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。 解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。 示例 1: 输入:nums = [1,2,3] 输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] 示例 2: 输入:nums = [0] 输出:[[],[0]] 提示: 1 <= nums.length <…
原文链接: https://leetcode-cn.com/problems/uUsW3B 中文题目给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。 示例 1: 输入: n = 4, k = 2 输出: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 示例 2: 输入: n = 1, k = 1 输出: [[1]] 提示: 1 <= n <= 20 1 <= k <= n 注意:本题与主站 77 题相同: https://…
上一页
3 / 3