LeetCode //C - 7. Reverse Integer
: Example 3: Constraints: − 2 31 < = x < = 2 31 − 1 -2^{31} <= x <= 2^{31} - 1 −231<=x<=231−1 From: LeetCode Link: 7. Reverse Integer Solution: Ideas: 1. Initialize a result variable (reversed) to zero: This ...
LeetCode //C - 60. Permutation Sequence
permutation sequence. Example 1: Example 2: Example 3: Constraints: 1 <= n <= 91 <= k <= n! From: LeetCode Link: 60. Permutation Sequence Solution: Ideas: Factorial Calculation: The function starts by calcu...
LeetCode //C - 65. Valid Number
nglish letters (both uppercase and lowercase), digits (0-9), plus ‘+’, minus ‘-’, or dot ‘.’. From: LeetCode Link: 65. Valid Number Solution: Ideas: 1. Flag Variables: numSeen: This flag indicates whether at ...
【Leetcode】二叉树基础题思路
🔥个人主页:Quitecoder 🔥专栏:Leetcode刷题 目录 1.单值二叉树2.相同的树3.对称二叉树4.另一棵树的子树 1.单值二叉树 单值二叉树是所有节点的值都相同的二叉树。实现这个检查的思路是通过递归方式遍历整棵树,并验证每个节点是否满足单值二叉树的条件 具体来说,递归函数 isUnivalTree 的工作流程如下: 基本情况: 如果当前节点 (root) 为空 (NULL),那么根据单值树的定义...
【代码随想录刷题记录】LeetCode209长度最小的子数组
题目地址 1. 思路 1.1 基本思路及代码实现 按照卡尔老师的思路,这个题目涉及到了一个重要的知识:滑动窗口,(卡尔老师的图片演示比我做的好,就看卡尔老师的图片演示就行,其中我的fast指针对应卡尔老师的j指针,我的slow指针对应卡尔老师的i指针),所谓滑动窗口和快慢指针差不多,我最开始的想法是这样的:用快慢指针slow和fast遍历这个数组,用一个整型变量sum保存每次子数组的求和结果,为了能够用一次fo...
LeetCode //C - 47. Permutations II
in any order. Example 1: Example 2: Constraints: 1 <= nums.length <= 8-10 <= nums[i] <= 10 From: LeetCode Link: 47. Permutations II Solution: Ideas: 1. Sorting the Array: The function starts by sorting the...
【leetcode面试经典150题】73. 从中序与后序遍历序列构造二叉树(C++)
【题目描述】 给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。 【示例一】 输入:inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]输出:[3,9,20,null,null,15,7] 【示例二】 输入:inorder = [-1],...
LeetCode //C - 37. Sudoku Solver
= 9board[i][j] is a digit or ‘.’.It is guaranteed that the input board has only one solution. From: LeetCode Link: 29. Divide Two Integers Solution: Ideas: Sudoku Rules: To solve Sudoku, the code must respect...
LeetCode //C - 29. Divide Two Integers
2 31 − 1 -2^{31} <= dividend, divisor <= 2^{31} - 1 −231<=dividend,divisor<=231−1divisor != 0 From: LeetCode Link: 29. Divide Two Integers Solution: Ideas: Handle Signs: Compute the sign of the result based o...
【代码随想录刷题记录】LeetCode367有效的完全平方数
题目地址 1. 思路 这个题就用二分查找的思想,比LeetCode69x的平方根要简单一些,那个还要处理开平方不是整数的情况,这个直接就按左闭右闭,middle的平方是num就返回true,否则继续迭代二分直到找到middle的平方是num的情况返回true,或者找不到跳出循环返回false. 2. 代码 class Solution {public: //左闭右闭 bool isPerfectSquare(...