LeetCode-HOT-100
LeetCode-HOT-100 copied to clipboard
力扣 (LeetCode) 🔥LeetCode HOT 100
# [10\. 正则表达式匹配](https://leetcode.cn/problems/regular-expression-matching/) ## Description Difficulty: **困难** Related Topics: [递归](https://leetcode.cn/tag/recursion/), [字符串](https://leetcode.cn/tag/string/), [动态规划](https://leetcode.cn/tag/dynamic-programming/) 给你一个字符串 `s` 和一个字符规律 `p`,请你来实现一个支持 `'.'` 和 `'*'` 的正则表达式匹配。 * `'.'` 匹配任意单个字符 * `'*'` 匹配零个或多个前面的那一个元素 所谓匹配,是要涵盖 **整个 **字符串 `s`的,而不是部分字符串。...
# [739\. 每日温度](https://leetcode.cn/problems/daily-temperatures/) ## Description Difficulty: **中等** Related Topics: [栈](https://leetcode.cn/tag/stack/), [数组](https://leetcode.cn/tag/array/), [单调栈](https://leetcode.cn/tag/monotonic-stack/) 给定一个整数数组 `temperatures` ,表示每天的温度,返回一个数组 `answer` ,其中 `answer[i]` 是指对于第 `i` 天,下一个更高温度出现在几天后。如果气温在这之后都不会升高,请在该位置用 `0` 来代替。 **示例 1:** ``` 输入: temperatures = [73,74,75,71,69,72,76,73]...
# [647\. 回文子串](https://leetcode.cn/problems/palindromic-substrings/) ## Description Difficulty: **中等** Related Topics: [字符串](https://leetcode.cn/tag/string/), [动态规划](https://leetcode.cn/tag/dynamic-programming/) 给你一个字符串 `s` ,请你统计并返回这个字符串中 **回文子串** 的数目。 **回文字符串** 是正着读和倒过来读一样的字符串。 **子字符串** 是字符串中的由连续字符组成的一个序列。 具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被视作不同的子串。 **示例 1:** ``` 输入:s = "abc" 输出:3 解释:三个回文子串: "a",...
# [621\. 任务调度器](https://leetcode.cn/problems/task-scheduler/) ## Description Difficulty: **中等** Related Topics: [贪心](https://leetcode.cn/tag/greedy/), [数组](https://leetcode.cn/tag/array/), [哈希表](https://leetcode.cn/tag/hash-table/), [计数](https://leetcode.cn/tag/counting/), [排序](https://leetcode.cn/tag/sorting/), [堆(优先队列)](https://leetcode.cn/tag/heap-priority-queue/) 给你一个用字符数组 `tasks` 表示的 CPU 需要执行的任务列表。其中每个字母表示一种不同种类的任务。任务可以以任意顺序执行,并且每个任务都可以在 1 个单位时间内执行完。在任何一个单位时间,CPU 可以完成一个任务,或者处于待命状态。 然而,两个 **相同种类** 的任务之间必须有长度为整数`n`的冷却时间,因此至少有连续 `n` 个单位时间内 CPU 在执行不同的任务,或者在待命状态。...
# [617\. 合并二叉树](https://leetcode.cn/problems/merge-two-binary-trees/) ## Description Difficulty: **简单** Related Topics: [树](https://leetcode.cn/tag/tree/), [深度优先搜索](https://leetcode.cn/tag/depth-first-search/), [广度优先搜索](https://leetcode.cn/tag/breadth-first-search/), [二叉树](https://leetcode.cn/tag/binary-tree/) 给你两棵二叉树: `root1` 和 `root2` 。 想象一下,当你将其中一棵覆盖到另一棵之上时,两棵树上的一些节点将会重叠(而另一些不会)。你需要将这两棵树合并成一棵新二叉树。合并的规则是:如果两个节点重叠,那么将这两个节点的值相加作为合并后节点的新值;否则,**不为** null 的节点将直接作为新二叉树的节点。 返回合并后的二叉树。 **注意:** 合并过程必须从两个树的根节点开始。 **示例 1:**  ``` 输入:root1 =...
# [581\. 最短无序连续子数组](https://leetcode.cn/problems/shortest-unsorted-continuous-subarray/) ## Description Difficulty: **中等** Related Topics: [栈](https://leetcode.cn/tag/stack/), [贪心](https://leetcode.cn/tag/greedy/), [数组](https://leetcode.cn/tag/array/), [双指针](https://leetcode.cn/tag/two-pointers/), [排序](https://leetcode.cn/tag/sorting/), [单调栈](https://leetcode.cn/tag/monotonic-stack/) 给你一个整数数组 `nums` ,你需要找出一个 **连续子数组** ,如果对这个子数组进行升序排序,那么整个数组都会变为升序排序。 请你找出符合题意的 **最短** 子数组,并输出它的长度。 **示例 1:** ``` 输入:nums = [2,6,4,8,10,9,15] 输出:5...
# [560\. 和为 K 的子数组](https://leetcode.cn/problems/subarray-sum-equals-k/) ## Description Difficulty: **中等** Related Topics: [数组](https://leetcode.cn/tag/array/), [哈希表](https://leetcode.cn/tag/hash-table/), [前缀和](https://leetcode.cn/tag/prefix-sum/) 给你一个整数数组 `nums` 和一个整数 `k` ,请你统计并返回 _该数组中和为 `k`的连续子数组的个数 _。 **示例 1:** ``` 输入:nums = [1,1,1], k =...
# [543\. 二叉树的直径](https://leetcode.cn/problems/diameter-of-binary-tree/) ## Description Difficulty: **简单** Related Topics: [树](https://leetcode.cn/tag/tree/), [深度优先搜索](https://leetcode.cn/tag/depth-first-search/), [二叉树](https://leetcode.cn/tag/binary-tree/) 给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。 **示例 :** 给定二叉树 ``` 1 / \ 2 3 / \ 4 5 ``` 返回 **3**, 它的长度是路径...
# [538\. 把二叉搜索树转换为累加树](https://leetcode.cn/problems/convert-bst-to-greater-tree/) ## Description Difficulty: **中等** Related Topics: [树](https://leetcode.cn/tag/tree/), [深度优先搜索](https://leetcode.cn/tag/depth-first-search/), [二叉搜索树](https://leetcode.cn/tag/binary-search-tree/), [二叉树](https://leetcode.cn/tag/binary-tree/) 给出二叉 **搜索** 树的根节点,该树的节点值各不相同,请你将其转换为累加树(Greater Sum Tree),使每个节点 `node` 的新值等于原树中大于或等于 `node.val` 的值之和。 提醒一下,二叉搜索树满足下列约束条件: * 节点的左子树仅包含键 **小于** 节点键的节点。 * 节点的右子树仅包含键 **大于**...
# [494\. 目标和](https://leetcode.cn/problems/target-sum/) ## Description Difficulty: **中等** Related Topics: [数组](https://leetcode.cn/tag/array/), [动态规划](https://leetcode.cn/tag/dynamic-programming/), [回溯](https://leetcode.cn/tag/backtracking/) 给你一个整数数组 `nums` 和一个整数 `target` 。 向数组中的每个整数前添加 `'+'` 或 `'-'` ,然后串联起所有整数,可以构造一个 **表达式** : * 例如,`nums = [2, 1]` ,可以在...