operations leetcode minimum halve
LeetCode 51. N 皇后
``` class Solution { public: vector> res; vector path; vector anti_diag,col,diag; void dfs(int n,int u) { if(u==n) { res.push_back(path); return; } st ......
leetCode1768.交替合并字符串 && [1679] K 和数对的最大数目
题目:给你两个字符串 word1 和 word2 。请你从 word1 开始,通过交替添加字母来合并字符串。如果一个字符串比另一个字符串长,就将多出来的字母追加到合并后字符串的末尾。返回 合并后的字符串 。 输入:word1 = "abc", word2 = "pqr" 输出:"apbqcr" 解释 ......
LeetCode/区间子数组个数
给你一个整数数组 nums 和两个整数:left 及 right 找出 nums 中连续、非空且其中最大元素在范围 [left, right] 内的子数组,并返回满足条件的子数组的个数 ###1. 遍历区间右端点 + 同时记录满足条件的左边点位 数组中不能含有大于 right的元素, 且至少含有一个 ......
二刷Leetcode-Days10
1. 二叉树 /** * 102. BinaryTree的层序遍历(借助辅助队列实现,递归法pass) * @param root * @return */ public List<List<Integer>> levelOrder(TreeNode root) { List<List<Intege ......
LeetCode 93. 复原IP地址
``` class Solution { public: vector res; void dfs(string s,string path,int idx,int cnt)//枚举下一个逗号填哪 { if(idx>=s.size()) { if(idx==s.size()&&cnt==4) { p ......
二叉搜索二叉搜索树-leetcode-700
给定二叉搜索树(BST)的根节点 root 和一个整数值 val。 你需要在 BST 中找到节点值等于 val 的节点。 返回以该节点为根的子树。 如果节点不存在,则返回 null 。 示例 1: 输入:root = [4,2,7,1,3], val = 2 输出:[2,1,3] 示例 2: 输入: ......
【LeetCode.384打乱数组】Knuth洗牌算法详解
前两天看网易面筋得知网易云的随机歌曲播放使用了这个算法,遂找题来做做学习一下 ### 打乱数组 https://leetcode.cn/problems/shuffle-an-array/ 给你一个整数数组 nums ,设计算法来打乱一个没有重复元素的数组。打乱后,数组的所有排列应该是 **等可能* ......
LeetCode hints
通过样例得到一些通用性质,从单点出发结合要求什么,初步判断可以应用什么算法,之前见没见过类似的,见过就转换成之前会做的,怎么转换需要思考。 想不出来可以先出朴素的算法,然后才考虑优化 正着推不行就倒着推 结果和顺序无关就可以sort数组,复杂的需要sort index(由小到大排序且保持原序) in ......
Leetcode 1171. 从链表中删去总和值为零的连续节点
### 题目: 给你一个链表的头节点 `head`,请你编写代码,反复删去链表中由 **总和** 值为 `0` 的连续节点组成的序列,直到不存在这样的序列为止。 删除完毕后,请你返回最终结果链表的头节点。 你可以返回任何满足题目要求的答案。 (注意,下面示例中的所有序列,都是对 `ListNode` ......
LeetCode 双周赛 106(2023/06/10)两道思维题
> **本文已收录到 [AndroidFamily](https://github.com/pengxurui/AndroidFamily),技术和职场问题,请关注公众号 [彭旭锐] 加入知识星球提问。** - 往期回顾:[LeetCode 单周赛第 348 场 · 数位 DP 模版学会了吗?](h ......
LeetCode 491. 递增子序列
``` class Solution { public: vector> ans; vector path; void dfs(vector nums,int idx)//选择path的下一个数填什么,从下标idx开始选 { if(path.size()>=2) ans.push_back(path ......
LeetCode----二分查找
# 1 算法原理 **适用条件:有序数组** # 2 算法模板 ```python class Solution: def search(self, nums: List[int], target: int) -> int: left = 0 right = len(nums) - 1 # 规则 [ ......
LeetCode 47. 全排列 II
``` class Solution { public: vector> res; vector path; bool st[10]; void dfs(vector nums,int u) { if(u==nums.size()) { res.push_back(path); return; } ......
【LeetCode SQL 70】
# Table of Contents ### SQL基础 [1068. 产品销售分析 I](https://leetcode.cn/problems/product-sales-analysis-i/) * [NumPy Arrays](#numpyarrays) * [NumPy Indexin ......
构建编译dockerfile docker build报错make: uname: Operation not permitted
报错信息: ![](https://img2023.cnblogs.com/blog/1138462/202306/1138462-20230609223131312-1389627832.png) 查看docker版本 ![](https://img2023.cnblogs.com/blog/11 ......
重载全局operator_new制造bug
[toc] * main.cpp编译后链接libA.so,如果libA.so的开发者重载了全局::operator new(size_t) 展开查看 // A.cpp的重载了全局::operator new(size_t)代码如下 // 使用 g++ -shared -fPIC -o libA.so ......
Leetcode 刷题顺序,看这一篇就够了!(第二版)
来源:https://mp.weixin.qq.com/s/APGE0k73n4Hk2bvyySWVDA 第一天(周一) 1、Python 语法知识 2、Java 语法知识 “ 1、参考网站:https://www.runoob.com/ 2、只需要掌握相关编程语言的基础语法、对象初始化、基本数据类 ......
Leetcode Hot 100 & 128. Longest Consecutive Sequence
参考资料: 考点:哈希 & [题干] Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its len ......
LeetCode> 69. 求x的平方根
[TOC] # 题目 地址:[LeetCode 69. x的平方根](https://leetcode.cn/problems/sqrtx/) # 题目描述 给你一个非负整数 x ,计算并返回 x 的 算术平方根 。 由于返回类型是整数,结果只保留 整数部分 ,小数部分将被 舍去 。 注意:不允许使 ......
【LeetCode滑动窗口专题#2】无重复字符的最长子串
[#1传送门](https://www.cnblogs.com/DAYceng/p/17263069.html) [滑动窗口最大值](https://www.cnblogs.com/DAYceng/p/17124469.html#%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A ......
LeetCode 2116. 判断一个括号字符串是否有效
````java import java.util.ArrayDeque; import java.util.Deque; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.u ......
LeetCode 剑指 Offer 65. 不用加减乘除做加法
````java /** * 写一个函数,求两个整数之和,要求在函数体内不得使用 “+”、“-”、“*”、“/” 四则运算符号。 * * 示例: * 输入: a = 1, b = 1 * 输出: 2 * * 提示: * a, b 均可能是负数或 0 * 结果不会溢出 32 位整数 * * 0000 ......
LeetCode----前缀和
# 1 算法原理 **适用场景:利用preSum 数组,可以在O(1)的时间内快速求出nums任意区间[i,j]内的所有元素之和** **sum(i,j) = preSum(j + 1) - preSum[i]** ![](https://img2023.cnblogs.com/blog/21670 ......
LeetCode----回溯
# 1 算法模板 ``` for 选择 in 选择列表: # 做选择 将该选择从选择列表移除 路径.add(选择) backtrack(路径, 选择列表) # 撤销选择 路径.remove(选择) 将该选择再加入选择列表 ``` # 2 代码示例 [46. 全排列](https://leetcode ......
LeetCode----二维网格DFS
# 1 算法模板 ``` void dfs(int[][] grid, int r, int c) { // 判断 base case // 如果坐标 (r, c) 超出了网格范围,直接返回 if (!inArea(grid, r, c)) { return; } // 访问上、下、左、右四个相邻结 ......
[LeetCode] 1351. Count Negative Numbers in a Sorted Matrix
Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid. Exampl ......
递归-二叉搜索树-leetcode98验证二叉搜索树
```java //leetcode submit region begin(Prohibit modification and deletion) /** * Definition for a binary tree node. * public class TreeNode { * int va ......
LeetCode35.搜索插入位置
//个人学习笔记用 - 题目: 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 请必须使用时间复杂度为 O(log n) 的算法。 参考题解--代码随想录 - 暴力解法: ~~~c++ class Solution { pub ......
LeetCode 90. 子集 II
``` class Solution { public: unordered_map cnt; vector> res; vector path; vector> subsetsWithDup(vector& nums) { for(auto i:nums) cnt[i]++; dfs(-10);/ ......