leetcode回溯
Bryan要加油
这个作者很懒,什么都没留下…
展开
-
剑指 Offer 38. 字符串的排列[Medium](Leetcode每日一题-2021.06.22)
Problem输入一个字符串,打印出该字符串中字符的所有排列。你可以以任意顺序返回这个字符串数组,但里面不能有重复元素。限制:1 <= s 的长度 <= 8Example输入:s = “abc”输出:[“abc”,“acb”,“bac”,“bca”,“cab”,“cba”]Solutionclass Solution {public: vector<string> permutation(string s) { vector<原创 2021-06-22 08:32:06 · 592 阅读 · 0 评论 -
1239. Maximum Length of a Concatenated String with Unique Char[Medium](Leetcode每日一题-2021.06.19)--抄答案
ProblemGiven an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.Return the maximum possible length of s.原创 2021-06-21 22:23:17 · 339 阅读 · 0 评论 -
842. Split Array into Fibonacci Sequence(Leetcode每日一题-2020.12.08)
ProblemGiven a string S of digits, such as S = “123456579”, we can split it into a Fibonacci-like sequence [123, 456, 579].Formally, a Fibonacci-like sequence is a list F of non-negative integers such that:0 <= F[i] <= 2^31 - 1, (that is, each int原创 2020-12-08 21:52:34 · 137 阅读 · 0 评论 -
Leetcode 78. Subsets && Leetcode 90. Subsets II
78. SubsetsProblemGiven an integer array nums, return all possible subsets (the power set).The solution set must not contain duplicate subsets.Example1Input: nums = [1,2,3]Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]Example2Input: nums = [原创 2020-11-22 19:54:00 · 149 阅读 · 0 评论 -
52. N-Queens II(Leetcode每日一题-2020.10.17)
ProblemThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return the number of distinct solutions to the n-queens puzzle.ExampleInput: 4Output: 2Explanation: The原创 2020-10-17 21:28:54 · 525 阅读 · 0 评论 -
113. Path Sum II(Leetcode每日一题-2020.09.26)
ProblemGiven a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.Note: A leaf is a node with no children.ExampleGiven the below binary tree and sum = 22,Return:Solution/** * Definition for a binary tree原创 2020-09-26 12:14:25 · 344 阅读 · 0 评论 -
78. Subsets(Leetcode每日一题-2020.09.20)
ProblemGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.ExampleInput: nums = [1,2,3]Output:[[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]Solutioncla原创 2020-09-20 11:01:54 · 203 阅读 · 0 评论 -
47. Permutations II(Leetcode每日一题-2020.09.18)
ProblemGiven a collection of numbers that might contain duplicates, return all possible unique permutations.ExampleInput: [1,1,2]Output:[[1,1,2],[1,2,1],[2,1,1]]Solutionclass Solution {public: vector<vector<int>> ret;原创 2020-09-18 20:34:01 · 401 阅读 · 0 评论 -
37. Sudoku Solver(Leetcode每日一题-2020.09.15)
ProblemWrite a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in each row.Each of the digits 1-9 must occur exactly once in each colum原创 2020-09-15 21:28:16 · 802 阅读 · 0 评论 -
79. Word Search(Leetcode每日一题-2020.09.13)
ProblemGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used原创 2020-09-13 21:50:25 · 593 阅读 · 0 评论 -
216. Combination Sum III(Leetcode每日一题-2020.09.11)
ProblemFind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Note:All numbers will be positive integers.The solution set must not c原创 2020-09-11 20:21:01 · 206 阅读 · 0 评论 -
40. Combination Sum II(Leetcode每日一题-2020.09.10)
ProblemGiven a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidates may only be used once in the combination.Note:All原创 2020-09-10 19:39:01 · 146 阅读 · 0 评论 -
39. Combination Sum(Leetcode每日一题-2020.09.09)
ProblemGiven a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same repeated number may be chosen from candidates unlimited原创 2020-09-09 21:54:30 · 199 阅读 · 0 评论 -
77. Combinations(Leetcode每日一题-2020.09.08)
ProblemGiven two integers n and k, return all possible combinations of k numbers out of 1 … n.You may return the answer in any order.Constraints:1 <= n <= 201 <= k <= nExample1Input: n = 4, k = 2Output:[[2,4],[3,4],[2,3],[1,2],原创 2020-09-08 21:04:26 · 162 阅读 · 0 评论 -
51. N-Queens(Leetcode每日一题-2020.09.03)
ProblemThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board configuration原创 2020-09-03 21:16:57 · 215 阅读 · 0 评论 -
491. Increasing Subsequences(Leetcode每日一题-2020.08.25)
ProblemGiven an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2.Constraints:The length of the given array will not exceed 15.Th原创 2020-08-25 21:51:17 · 106 阅读 · 0 评论 -
1079. Letter Tile Possibilities
ProblemYou have a set of tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make.Example1Input: “AAB”Output: 8Exp...原创 2020-04-25 13:11:32 · 288 阅读 · 0 评论 -
22. Generate Parentheses(Leetcode每日一题-2020.04.09)
ProblemGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example1Given n = 3, a solution set is:[ “((()))”, “(()())”, “(())()”, “()(()...原创 2020-04-09 22:46:03 · 154 阅读 · 0 评论 -
78. Subsets && 面试题 08.04. Power Set LCCI
ProblemProblem 78Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.面试题 08.04Write a method to return al...原创 2020-03-30 20:27:59 · 267 阅读 · 0 评论 -
47. Permutations II && 面试题 08.08. Permutation II LCCI && 面试题38. 字符串的排列
Problem47Given a collection of numbers that might contain duplicates, return all possible unique permutations.ExampleInput: [1,1,2]Output:[[1,1,2],[1,2,1],[2,1,1]]面试题08.08Write a method ...原创 2020-03-29 17:21:57 · 246 阅读 · 0 评论 -
46. Permutations&&面试题 08.07. Permutation I LCCI(Leetcode每日一题-2020.04.25)
Problem46Given a collection of distinct integers, return all possible permutations.ExampleInput: [1,2,3]Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]来源:力扣(LeetCode)链接:https...原创 2020-03-29 17:12:33 · 291 阅读 · 0 评论 -
面试题57 - II. 和为s的连续正数序列(Leetcode每日一题-2020.03.06)
Problem输入一个正整数 target ,输出所有和为 target 的连续正整数序列(至少含有两个数)。序列内的数字由小到大排列,不同序列按照首个数字从小到大排列。限制:1 <= target <= 10^5Example1输入:target = 9输出:[[2,3,4],[4,5]]Example2输入:target = 15输出:[[1,2,3,4,5...原创 2020-03-06 19:19:26 · 172 阅读 · 0 评论 -
面试题 04.12. Paths with Sum LCCI
ProblemYou are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The ...原创 2020-03-04 20:10:24 · 221 阅读 · 0 评论 -
113. Path Sum II && 面试题34. 二叉树中和为某一值的路径
Problem113Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.Note: A leaf is a node with no children.ExampleGiven the below binary tree and sum ...原创 2020-03-03 22:48:59 · 188 阅读 · 0 评论 -
993. Cousins in Binary Tree
ProblemIn a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.Two nodes of a binary tree are cousins if they have the same depth, but have different parent...原创 2020-03-02 21:00:36 · 200 阅读 · 0 评论 -
1022. Sum of Root To Leaf Binary Numbers
ProblemGiven a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 ->...原创 2020-02-27 23:11:43 · 196 阅读 · 0 评论