leetcode面试经典150题】62. K 个一组翻转链表(C++)

【题目描述】 给你链表的头节点 head ,每 k 个节点一组进行翻转,请你返回修改后的链表。 k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原有顺序。 你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。 【示例一】 输入:head = [1,2,3,4,5], k = 2输出:[2,1,4,3,5] 【示例二】 输入:head = [1,2...

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...

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 - 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 //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面试经典150题】75. 二叉树展开为链表(C++)

【题目描述】 给你二叉树的根结点 root ,请你将它展开为一个单链表: 展开后的单链表应该同样使用 TreeNode ,其中 right 子指针指向链表中下一个结点,而左子指针始终为 null 。展开后的单链表应该与二叉树 先序遍历 顺序相同。 【示例一】 输入:root = [1,2,5,3,4,null,6]输出:[1,null,2,null,3,null,4,null,5,null,6] 【示例二】 ...

leetcode51.N皇后(困难)-回溯法

 思路 都知道n皇后问题是回溯算法解决的经典问题,但是用回溯解决多了组合、切割、子集、排列问题之后,遇到这种二维矩阵还会有点不知所措。 首先来看一下皇后们的约束条件: 不能同行不能同列不能同斜线 确定完约束条件,来看看究竟要怎么去搜索皇后们的位置,其实搜索皇后的位置,可以抽象为一棵树。 下面我用一个 3 * 3 的棋盘,将搜索过程抽象为一棵树,如图:  从图中,可以看出,二维矩阵中矩阵的高就是这棵树的高度,矩阵...

【代码随想录刷题记录】LeetCode209长度最小的子数组

题目地址 1. 思路 1.1 基本思路及代码实现 按照卡尔老师的思路,这个题目涉及到了一个重要的知识:滑动窗口,(卡尔老师的图片演示比我做的好,就看卡尔老师的图片演示就行,其中我的fast指针对应卡尔老师的j指针,我的slow指针对应卡尔老师的i指针),所谓滑动窗口和快慢指针差不多,我最开始的想法是这样的:用快慢指针slow和fast遍历这个数组,用一个整型变量sum保存每次子数组的求和结果,为了能够用一次fo...
© 2024 LMLPHP 关于我们 联系我们 友情链接 耗时0.012867(s)
2024-05-05 20:26:54 1714912014