add-two-numbers-ii leetcode problems numbers

[LeetCode Hot 100] LeetCode543. 二叉树的直径

题目描述 思路 所谓二叉树的直径,就是左右子树的最大深度之和。 方法一: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; ......
LeetCode 直径 Hot 100 543

[LeetCode Hot 100] LeetCode104. 二叉树的最大深度

题目描述 思路 熟练掌握二叉树的遍历算法 方法一:层序遍历(迭代)+计数 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; ......
LeetCode 深度 Hot 100 104

[LeetCode Hot 100] LeetCode102. 二叉树的层序遍历

题目描述 思路 方法一:递归 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * Tree ......
LeetCode Hot 100 102

[LeetCode Hot 100] LeetCode144. 二叉树的前序遍历

题目描述 思路 熟练掌握迭代和递归的代码。 递归代码:额外写一个函数void preOrder(TreeNode node, List res) 迭代代码:会用到数据结构——栈。先入栈当前节点的右子节点,再入栈左子节点。 方法一:递归 /** * Definition for a binary tr ......
LeetCode Hot 100 144

[LeetCode Hot 100] LeetCode94. 二叉树的中序遍历

题目描述 思路 熟练掌握迭代和递归的代码。 递归:额外写一个函数void inOrder(TreeNode node, List res) 迭代:令cur = root,一直往左子树找,找到最后一个左子节点,当cur为空,就开始处理栈顶元素(将栈顶元素加入结果集),随后将cur设置为右子节点,继续执 ......
LeetCode Hot 100 94

[LeetCode Hot 100] LeetCode145. 二叉树的后序遍历

题目描述 思路 递归:额外写一个函数void postOrder(TreeNode node, List res) 迭代: 前序遍历:根 左 右 将前序遍历改造成:根 右 左 然后反转根右左为:左 右 根,即为后序遍历 优化一下: while (!stack.isEmpty()) { TreeNod ......
LeetCode Hot 100 145

Leetcode每日一题

目录202312/2512/2612/27 2023 12月往前的应该就不会补题解了,大概有时间会往前一直补到12/1的题解 12/25 1276. 不浪费原料的汉堡制作方案 题目分析: 数学题,解二元一次方程即可 具体过程有$$\left { \begin{array}{c}4x+2y=tomat ......
Leetcode

【动态规划】leetcode 不同路径问题

题目名称:63. 不同路径 II 链接:https://leetcode.cn/problems/unique-paths-ii/description/ 题目内容: 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。 机器人每次只能向下或者向右移动一步。机器 ......
路径 leetcode 动态 问题

[LeetCode] 2660. Determine the Winner of a Bowling Game

You are given two 0-indexed integer arrays player1 and player2, that represent the number of pins that player 1 and player 2 hit in a bowling game, re ......
Determine LeetCode Bowling Winner 2660

D. Yet Another Inversions Problem

D. Yet Another Inversions Problem You are given a permutation $p_0, p_1, \ldots, p_{n-1}$ of odd integers from $1$ to $2n-1$ and a permutation $q_0, q ......
Inversions Another Problem Yet

Qt小技巧17.使用魔法数(Magic Number)

1 什么是魔法数? 当使用 QDataStream 进行数据流读写时,魔法数(Magic Number)是用于标识特定文件格式或数据结构的固定数值或字节序列。 魔法数是一个固定的数值或字节序列,用于识别特定文件格式或数据表示方式,在读取操作中起到了一个检测标识的作用,可以帮助确定所读取的文件是否符合 ......
技巧 Number 魔法 Magic 17

leetcode 1633. 各赛事的用户注册率

https://leetcode.cn/problems/percentage-of-users-attended-a-contest/?envType=study-plan-v2&envId=sql-free-50 聚合函数分组后计算的是一组内的数据, 分组前我们认为所有数据是一组 本题注意还需要 ......
赛事 leetcode 用户注册 用户 1633

【LeetCode】131. 分割回文串

题目 给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是 回文串 。返回 s 所有可能的分割方案。 回文串 是正着读和反着读都一样的字符串。 示例 1: 输入:s = "aab" 输出:[["a","a","b"],["aa","b"]] 示例 2: 输入:s = "a" 输出:[["a ......
回文 LeetCode 131

【LeetCode】17. 电话号码的字母组合

链接: https://leetcode.cn/problems/letter-combinations-of-a-phone-number/ 思路: 利用深度优先遍历 遍历两个空间 第一个空间是digits,命名为space1 第二个空间是digits的每一位自身的空间,命名为space2 关键是 ......
电话号码 字母 LeetCode 号码 电话

【LeetCode】39. 组合总和

题目 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。 candidates 中的 同一个 数字可以 无限制重复被选取 ......
总和 LeetCode 39

【LeetCode】79. 单词搜索

链接: https://leetcode.cn/problems/word-search/ 思路: 利用深度优先遍历 深度优先遍历一般流程: 判断当前是否符合要求 若符合要求,则看更深一层是否符合要求 最后逐层向上返回 代码 class Solution: def exist(self, board ......
单词 LeetCode 79

Leetcode LCP 02. 分式化简

https://leetcode.cn/problems/deep-dark-fraction/description/ 有一个同学在学习分式。他需要将一个连分数化成最简分数,你能帮助他吗? 连分数是形如上图的分式。在本题中,所有系数都是大于等于0的整数。 输入的cont代表连分数的系数(cont[ ......
分式 Leetcode LCP 02

Leetcode LCP 14. 切分数组

https://leetcode.cn/problems/qie-fen-shu-zu/description/ 给定一个整数数组 nums ,小李想将 nums 切割成若干个非空子数组,使得每个子数组最左边的数和最右边的数的最大公约数大于 1 。 为了减少他的工作量,请求出最少可以切成多少个子数组 ......
数组 Leetcode LCP 14

『LeetCode』9. 回文数 Palindrome Number

题目描述 给你一个整数x,如果x是一个回文整数,返回true;否则,返回false。 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 例如,121是回文,而123不是。 示例 1: 输入:x = 121 输出:true 示例 2: 输入:x = -121 输出:false 解释:从左 ......
回文 Palindrome LeetCode Number

CF1909F1 Small Permutation Problem (Easy Version)

给定一个长度为 \(n\) 的数组 \(a\),其中 \(a_i \in [1, n]\),试计算满足以下条件的 \([1, n]\) 的排列 \(p\) 的个数: \(\forall i \in [1, n], \sum_{1 \le j \le i} [p_j \le i] = a_i\) \( ......
Permutation Problem Version 1909F Small

CF1909F2 Small Permutation Problem (Hard Version)

给定一个长度为 \(n\) 的数组 \(a\),其中 \(a_i \in [-1, n]\),试计算满足以下条件的 \([1, n]\) 的排列 \(p\) 的个数: \(\forall i \in [1, n], \text{有 }\sum_{1 \le j \le i} [p_j \le i] ......
Permutation Problem Version 1909F Small

【模版】高精度减法 (A - B problem)

直接看代码和注释吧qwq高精度就是模拟嘛ww 还是python好,自带高精度 #include<bits/stdc++.h> #define MAXN 10500 using namespace std; string a, b; //选择字符串。因为字符串储存了每个串的长度,可以直接调用。 int ......
高精 减法 高精度 模版 problem

【模版】高精度乘法 (A*B problem)

和A+B problem类似 ,不多说,直接看代码和注释就好啦!ww 感觉这东西只要有个概念就行了...就是在练模拟?www其他语言似乎有大数加减乘除? 这样的高精度算法时间复杂度O(n2),n是数字位数,如果位数过大还是很慢。可以利用快速傅里叶变换的方式加速高精度乘法。(虽然都是我连傅里叶级数都没 ......
高精 乘法 高精度 模版 problem

『LeetCode』8. 字符串转换整数 (atoi) String to Integer (atoi)

题目描述 请你来实现一个myAtoi(string s)函数,使其能将字符串转换成一个 32 位有符号整数(类似 C/C++ 中的atoi函数)。 函数myAtoi(string s)的算法如下: 读入字符串并丢弃无用的前导空格 检查下一个字符(假设还未到字符末尾)为正还是负号,读取该字符(如果有) ......
整数 atoi 字符串 字符 LeetCode

[LeetCode Hot 100] LeetCode394. 字符串解码

题目描述 思路 思路: 碰到数字:压入数字栈,注意多位数的情况 碰到字母:直接拼接到res 遇到[:将num和res分别压入栈 遇到]:开始处理栈顶元素 方法一: class Solution { public String decodeString(String s) { int num = 0; ......
LeetCode 字符串 字符 Hot 100

『LeetCode』7. 整数反转 Reverse Integer

题目描述 给你一个 32 位的有符号整数x,返回将x中的数字部分反转后的结果。 如果反转后整数超过 32 位的有符号整数的范围 [−231, 231 − 1],就返回 0。 假设环境不允许存储 64 位整数(有符号或无符号)。 示例 1: 输入:x = 123 输出:321 示例 2: 输入:x = ......
整数 LeetCode Integer Reverse

[LeetCode Hot 100] LeetCode739. 每日温度

题目描述 思路:单调递减栈 使用单调栈的模板即可。 根据题意可知,该题使用的是单调递减栈。 问题抽象为:找出数组中右边第一个比我大的元素。 方法一: class Solution { public int[] dailyTemperatures(int[] temperatures) { // 用于 ......
LeetCode 温度 Hot 100 739

[LeetCode Hot 100] LeetCode42. 接雨水

题目描述 思路一:单调栈 柱子的高度递减的时候是装不了水的,当碰到第一个比之前高的柱子才可以装水。 此时计算栈顶索引能装的水: 宽:i - left - 1(这个left为栈顶元素pop之后的peek值) 高:min(height[left], height[i]) - height[top] 该题 ......
LeetCode 雨水 Hot 100 42

[LeetCode Hot 100] LeetCode84. 柱状图中最大的矩形

题目描述 思路:枚举+优化(单调栈) 先固定矩阵的高。 然后向左向右找到第一个比当前元素值小的元素,确定好左右边界。 对于元素2来说: 向左找到第一个比当前元素值小的元素:1的右边界 向右找到第一个比当前元素值小的元素:3的右边界 枚举每个元素的上边界,确定往左数最远到达哪个边界(即寻找左边第一个比 ......
LeetCode 矩形 Hot 100 84

CodeForces 1909F2 Small Permutation Problem (Hard Version)

洛谷传送门 CF 传送门 感觉这个题还是挺不错的。 考虑 F1。考察 \(a_i\) 差分后的意义,发现 \(a_i - a_{i - 1}\) 就是 \((\sum\limits_{j = 1}^{i - 1} [p_j = i]) + p_i \le i\)。 考虑将其转化为棋盘问题。在 \(( ......
共2070篇  :3/69页 首页上一页3下一页尾页