![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
递归
文章平均质量分 57
xiaocong1990
这个作者很懒,什么都没留下…
展开
-
[leetcode]beautiful-arrangement. 优美的排列
【代码】[leetcode]beautiful-arrangement. 优美的排列。原创 2024-06-27 15:20:02 · 248 阅读 · 0 评论 -
[leetcode]32. Longest Valid Parentheses
链接:https://leetcode.com/problems/longest-valid-parentheses/description/Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substri...原创 2018-05-13 16:33:26 · 126 阅读 · 1 评论 -
[leetcode] jump-game-v
即当我们需要计算 dp[i] 时,我们发现某个 dp[j] 没有计算过,接着在计算 dp[j] 时,又发现某个 dp[k] 没有计算过,以此类推,直到某次搜索时发现当前位置的 dp 值需要 dp[i] 的值才能得到,这样就出现了环。在本题中,根据第三个条件,arr[j] 是一定小于 arr[i] 的,即我们的搜索每深入一层,就跳到了高度更小的位置。记忆化搜索以深度优先搜索为基础,在第一次搜索到某个状态时,会将该状态与其对应的值存储下来,这样在未来的搜索中,如果搜索到相同的状态,就不用再进行重复搜索了。原创 2024-04-18 10:32:24 · 610 阅读 · 0 评论 -
[leetcode] max-area-of-island
(代表土地) 构成的组合,这里的「相邻」要求两个。如果没有岛屿,则返回面积为。,因为岛屿只能包含水平或垂直这四个方向上的。岛屿的面积是岛上值为。原创 2024-04-15 11:52:14 · 424 阅读 · 0 评论 -
[leetcode] all-nodes-distance-k-in-binary-tree 二叉树中所有距离为 K 的结点
若将 target\textit{target}target 当作树的根结点,我们就能从 target\textit{target}target 出发,使用深度优先搜索去寻找与 target\textit{target}target 距离为 kkk 的所有结点,即深度为 kkk 的所有结点。由于输入的二叉树没有记录父结点,为此,我们从根结点 root\textit{root}root 出发,使用深度优先搜索遍历整棵树,同时用一个哈希表记录每个结点的父结点。的所有结点的值的列表。给定一个二叉树(具有根结点。原创 2024-04-10 20:23:41 · 342 阅读 · 0 评论 -
[leetcode] 1306 Jump Game III
这里有一个非负整数数组 arr,你最开始位于该数组的起始下标 start 处。当你位于下标 i 处时,你可以跳到 i + arr[i] 或者 i - arr[i]。请你判断自己是否能够跳到对应元素值为 0 的 任一 下标处。注意,不管是什么情况下,你都无法跳到数组之外。原创 2023-01-11 11:19:21 · 223 阅读 · 0 评论 -
[leetcode]493. Reverse Pairs
链接:https://leetcode.com/problems/reverse-pairs/description/Given an arraynums, we call(i, j)animportant reverse pairifi < jandnums[i] > 2*nums[j].You need to return the number of importa...原创 2018-06-12 21:09:49 · 215 阅读 · 0 评论 -
[leetcode]数组中的逆序对
链接力扣在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。示例 1:输入: [7,5,6,4]输出: 5来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。方法一:归并排序预备知识「归并排序」是分治思想的典型应用,它包含.原创 2022-01-10 23:16:17 · 420 阅读 · 0 评论 -
[LeetCode] Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the...原创 2020-04-04 16:23:43 · 151 阅读 · 0 评论 -
[LeetCode] 78. Subsets
Given a set of distinct integers,S, return all possible subsets. Note:https://leetcode.com/problems/subsets/description/Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets.For example,If...原创 2020-04-04 10:34:59 · 150 阅读 · 0 评论 -
最近点对
算法: 0:把所有的点按照横坐标排序 1:用一条竖直的线L将所有的点分成两等份 2:递归算出左半部分的最近两点距离d1,右半部分的最近两点距离d2,取d=min(d1,d2) 3:算出“一个在左半部分,另一个在右半部分”这样的点对的最短距离d3。 4:结果=min(d1,d2,d3) 关键就是这第3步。貌似这需要n^2的时间原创 2018-04-06 18:21:44 · 550 阅读 · 0 评论 -
[lintcode]98. 链表排序
链接:http://www.lintcode.com/zh-cn/problem/sort-list/在 O(n log n) 时间复杂度和常数级的空间复杂度下给链表排序。您在真实的面试中是否遇到过这个题? Yes样例给出 1->3->2->null,给它排序变成 1->2->3->null.思路:对链原创 2018-04-08 19:01:37 · 296 阅读 · 0 评论 -
[leetcode]99. Recover Binary Search Tree
题目链接:https://leetcode.com/problems/recover-binary-search-tree/#/descriptionTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.原创 2017-06-04 20:37:49 · 317 阅读 · 0 评论 -
[leetcode]546. Remove Boxes
题目链接:https://leetcode.com/problems/remove-boxes/description/Given several boxes with different colors represented by different positive numbers. You may experience several rounds to remove box原创 2017-08-13 21:56:33 · 1348 阅读 · 0 评论 -
[leetcode]591. Tag Validator
题目链接:https://leetcode.com/problems/tag-validator/description/Given a string representing a code snippet, you need to implement a tag validator to parse the code and return whether it is valid. A原创 2017-09-09 20:26:06 · 348 阅读 · 0 评论 -
[leetcode]87. Scramble String
题目链接:https://leetcode.com/problems/scramble-string/description/ Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one...原创 2017-08-28 21:43:35 · 383 阅读 · 0 评论 -
[leetcode]46. Permutations
链接:https://leetcode.com/problems/permutations/description/Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1...原创 2018-08-07 17:38:24 · 161 阅读 · 0 评论 -
[leetcode]37. Sudoku Solver
题目链接:https://leetcode.com/problems/sudoku-solver/description/Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may as原创 2017-08-24 14:54:12 · 194 阅读 · 0 评论 -
[lintcode]779. Generalized Abbreviation
链接:http://www.lintcode.com/zh-cn/problem/generalized-abbreviation/Write a function to generate the generalized abbreviations of a word.您在真实的面试中是否遇到过这个题? Yes样例Give原创 2018-04-19 17:03:34 · 229 阅读 · 0 评论 -
[leetcode]140. Word Break II
链接:https://leetcode.com/problems/word-break-ii/description/Given anon-emptystringsand a dictionarywordDictcontaining a list ofnon-emptywords, add spaces insto construct a sentence wh...原创 2018-06-04 15:36:57 · 352 阅读 · 1 评论 -
[leetcode]839. Similar String Groups
链接:https://leetcode.com/problems/similar-string-groups/description/ Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y.For example, "ta...原创 2018-06-07 21:57:26 · 922 阅读 · 0 评论 -
[leetcode]214. Shortest Palindrome
链接:https://leetcode.com/problems/shortest-palindrome/description/ Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest ...原创 2018-06-01 20:30:35 · 146 阅读 · 0 评论 -
[leetcode]827. Making A Large Island
链接:https://leetcode.com/problems/making-a-large-island/description/In a 2D grid of 0s and 1s, we change at most one 0 to a 1.After, what is the size of the largest island? (An island is a 4-directiona...原创 2018-06-08 20:50:22 · 554 阅读 · 0 评论 -
[leetcode]47. Permutations II
链接:https://leetcode.com/problems/permutations-ii/description/ Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Outpu...原创 2018-08-07 17:54:22 · 163 阅读 · 0 评论 -
[lintcode]136. 分割回文串
链接:https://lintcode.com/problem/palindrome-partitioning/description描述给定一个字符串s,将s分割成一些子串,使每个子串都是回文串。返回s所有可能的回文串分割方案。您在真实的面试中是否遇到过这个题? 是样例给出 s = "aab",返回[ ["aa", "b"], ["a", "a", ...原创 2018-09-03 12:58:00 · 176 阅读 · 0 评论 -
[leetcode]39. Combination Sum
链接:https://leetcode.com/problems/combination-sum/description/Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidat...原创 2018-09-05 21:45:55 · 129 阅读 · 0 评论 -
[leetcode]40. Combination Sum II
链接:https://leetcode.com/problems/combination-sum-ii/description/ Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where...原创 2018-09-05 21:54:22 · 125 阅读 · 0 评论 -
[leetcode]341. Flatten Nested List Iterator
题目链接:https://leetcode.com/problems/flatten-nested-list-iterator/?tab=DescriptionGiven a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or原创 2017-03-03 13:43:23 · 281 阅读 · 0 评论 -
[leetcode]282. Expression Add Operators
题目链接:https://leetcode.com/problems/expression-add-operators/description/Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not u原创 2017-08-25 15:15:18 · 214 阅读 · 0 评论 -
[leetcode]93. Restore IP Addresses
题目链接:https://leetcode.com/problems/restore-ip-addresses/tabs/description Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Gi...原创 2017-07-28 12:13:52 · 190 阅读 · 0 评论 -
[leetcode]494. Target Sum
题目链接:https://leetcode.com/problems/target-sum/You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choo原创 2017-02-04 22:52:58 · 620 阅读 · 0 评论 -
[leetcode]395. Longest Substring with At Least K Repeating Characters
题目链接:https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/#/description Find the length of the longest substring T of a given string (consists of lowercase letters ...原创 2017-05-07 17:30:07 · 235 阅读 · 0 评论 -
[leetcode]222. Count Complete Tree Nodes
题目链接:https://leetcode.com/problems/count-complete-tree-nodes/#/descriptionGiven a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a c原创 2017-05-24 21:21:56 · 282 阅读 · 0 评论 -
[leetcode]200. Number of Islands
题目链接:https://leetcode.com/problems/number-of-islands/#/descriptionGiven a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is form原创 2017-05-14 15:10:26 · 228 阅读 · 0 评论 -
[leetcode]372. Super Pow
题目链接:https://leetcode.com/problems/super-pow/#/descriptionYour task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of原创 2017-05-14 12:07:52 · 253 阅读 · 0 评论 -
[leetcode]50. Pow(x, n)
题目链接:https://leetcode.com/problems/powx-n/#/descriptionImplement pow(x,n).class Solution {public: double myPow(double x, int n) { if (n == 0) return 1.0; el原创 2017-05-12 18:04:05 · 173 阅读 · 0 评论 -
[leetcode]390. Elimination Game
题目链接:https://leetcode.com/problems/elimination-game/?tab=DescriptionThere is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number af原创 2017-03-04 10:58:27 · 305 阅读 · 0 评论 -
[leetcode]449. Serialize and Deserialize BST
题目链接:https://leetcode.com/problems/serialize-and-deserialize-bst/Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file原创 2017-01-16 11:24:03 · 321 阅读 · 0 评论 -
[leetcode]216. Combination Sum III
题目链接:https://leetcode.com/problems/combination-sum-iii/Find 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 combinati原创 2017-01-18 17:03:13 · 251 阅读 · 0 评论 -
[leetcode]22. Generate Parentheses
题目链接:https://leetcode.com/problems/generate-parentheses/Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a sol原创 2017-01-18 17:34:01 · 241 阅读 · 0 评论