operations leetcode minimum halve
LeetCode-Java题解 977. Squares of a Sorted Array
题目地址:[977. Squares of a Sorted Array](https://leetcode.cn/problems/squares-of-a-sorted-array/) 解题思路: 又是一道双指针的题目,看见秒想到双指针(平方直接调用sort方法也行,但是这么写这题就没意思了)。 ......
leetcode第105场双周赛
# 6394. 字符串中的额外字符 使用动态规划求解 详见代码: ```cpp class Solution { public: int minExtraChar(string s, vector& ct) { int n=s.size(); vector dp(n+1,n); dp[0]=0; f ......
力扣 662 https://leetcode.cn/problems/maximum-width-of-binary-tree/
需要了解树的顺序存储 如果是普通的二叉树 ,底层是用链表去连接的 如果是满二叉树,底层用的是数组去放的,而数组放的时候 会有索引对应 当前父节点是索引i,下一个左右节点就是2i,2i+1 利用满二叉树的索引特征 所以需要对每个节点进行一个索引赋值,赋值在队列中,队列用数组表示 核心代码如下 publ ......
CF1383E Strange Operation
首先可以发现对于一次操作,本质上就是删掉存在于两个 $1$ 之间的若干个 $0$ 的其中一个或者删掉两个连续的 $1$ 的其中一个。所以对于最终的 $01$ 串 $A$ ,令 $B$ 表示 $A$ 中两个 $1$ 之间的 $0$ 的个数,为了方便后面的计算,对于 $A$ 以 $1$ 开头或结尾,需要 ......
LeetCode 114. 二叉树展开为链表
# 思路1 ``` class Solution { public: void flatten(TreeNode* root) { while(root) { auto p=root->left; if(p)//找到左儿子的右链 { while(p->right) p=p->right; //将右链 ......
k8s的operator怎么使用
在Kubernetes中,Operator是一种用于管理和自动化应用程序的自定义控制器。它是一种自动化部署、配置和管理应用程序的扩展机制。下面是使用Kubernetes Operator的一般步骤: 安装Operator SDK:Operator SDK是一个用于开发Kubernetes Opera ......
Github疯传!谷歌师兄的LeetCode刷题笔记开源了!
有小伙伴私聊我说刚开始刷LeetCode的时候,感到很吃力,刷题效率很低。我以前刷题的时候也遇到这个问题,直到后来看到这个谷歌师兄总结的刷题笔记,发现LeetCode刷题都是套路呀,掌握这些套路之后,就变得非常简单了! 这份笔记是作者在找工作的时候,刷了几百道的LeetCode题目,然后按照数据结构 ......
Leetcode2585. 获得分数的方法数
![](https://img2023.cnblogs.com/blog/2533795/202305/2533795-20230525220020580-913191077.png) ## 题解 多重背包的模板 f[i][j]表示前i种题目得分为j的方案数 f[i][j] += f[i-1][j- ......
LeetCode/最小面积矩形
给一系列顶点,计算这些点能组成矩形的最小面积 ###1. 最小面积矩形(列举对角线+哈希) **矩形的边平行于x轴和y轴** 通过双重循环列举对角线顶点,计算满足条件的矩形面积 ``` class Solution { public: int minAreaRect(vector>& points) ......
Codeforces Round 837 (Div. 2) F. Hossam and Range Minimum Query
[传送门](https://codeforces.com/contest/1771/problem/F) 大致题意: ** 给一个n,然后给一个数组a, 有m个询问,询问区间[l, r]出现次数为奇数的最小值,若没有输出0, 每次输入的l,r需要异或上上一个答案,在第一个询问的时候认为上一个答案为0 ......
[LeetCode] 2451. Odd String Difference
You are given an array of equal-length strings words. Assume that the length of each string is n. Each string words[i] can be converted into a differe ......
python:Error: EPERM: operation not permitted, mkdir 'F:\Program Files\nodejs\node_global\node_modules'报错
可以发现文件没有权限 npm ERR! Error: EPERM: operation not permitted, mkdir 'F:\Program Files\nodejs\node_global\node_modules' 将nodejs的文件权限改为完全控制 之后操作即可 ......
每日一题 力扣 1377 https://leetcode.cn/problems/frog-position-after-t-seconds/
力扣 1377 https://leetcode.cn/problems/frog-position-after-t-seconds/ 这道题目用dp去做,构建邻接矩阵,做的时候需要注意题目条件,如果青蛙跳不动了,这个概率就保持不变了 一般跳青蛙,很容易想到dp 核心代码如下 public doub ......
[LeetCode] 1344. Angle Between Hands of a Clock 时钟指针的夹角
Given two numbers, `hour` and `minutes`, return *the smaller angle (in degrees) formed between the *`hour`* and the *`minute`* hand*. Answers within ` ......
LeetCode 98. 验证二叉搜索树
``` class Solution { public: vector dfs(TreeNode* root)//依次返回是否是二叉搜索树,最大值最小值 { vector res{1,root->val,root->val}; if(root->left) { auto l=dfs(root->le ......
LeetCode 222. 完全二叉树的节点个数
``` class Solution { public: int countNodes(TreeNode* root) { if(!root) return 0; auto l=root->left,r=root->right; int x=1,y=1;//记录左右两边层数 while(l) l=l ......
二刷Leetcode-Days07
动规: /** * 70. 爬楼梯 * @param n * @return */ public int climbStairs(int n) { if (n <= 2) { return n; } int[] dp = new int[n]; dp[0] = 1; dp[1] = 2; for ( ......
【双指针】LeetCode 340. 至多包含 K 个不同字符的最长子串
# 题目链接 [340. 至多包含 K 个不同字符的最长子串](https://leetcode.cn/problems/longest-substring-with-at-most-k-distinct-characters/description/ "340. 至多包含 K 个不同字符的最长子串 ......
[LeetCode] 1090. Largest Values From Labels
There is a set of n items. You are given two integer arrays values and labels where the value and the label of the ith element are values[i] and label ......
Educational Codeforces Round 148 (Rated for Div. 2) D1. Red-Blue Operations
[Easy Version传送门](https://codeforces.com/contest/1832/problem/D1) [Hard Version传送门](https://codeforces.com/contest/1832/problem/D1) 题目大意: ![](https:// ......
python:Error: EPERM: operation not permitted, mkdir 'F:\Program Files\nodejs\node_global\node_modules'报错
可以发现文件没有权限 npm ERR! Error: EPERM: operation not permitted, mkdir 'F:\Program Files\nodejs\node_global\node_modules' 将nodejs的文件权限改为完全控制 之后操作即可 ......
leetcode2215哈希列表的应用
哈希列表存储的是不重复的元素,使用两个哈希列表存储这两个数组。再遍历其中一个哈希列表,查看是否存在另一个哈希列表中 set.insert() set1.count(元素) for(int num:nums1){ set1.insert(num); } for(int num:set1){ if(!s ......
LeetCode 95. 不同的二叉搜索树 II
``` class Solution { public: vector dfs(int l,int r)//返回以n为根节点的所有可能子树 { vector res; if(l>r) return {NULL}; for(int k=l;k left=dfs(l,k-1); vector right ......
LeetCode 103. 二叉树的锯齿形层次遍历
``` class Solution { public: vector> res; void bfs(TreeNode* root) { queue q; q.push(root); int cnt=0; while(!q.empty()) { vector level; int len=q.siz ......
LeetCode 周赛 346(2023/05/21)仅 68 人 AK 的最短路问题
> **本文已收录到 [AndroidFamily](https://github.com/pengxurui/AndroidFamily),技术和职场问题,请关注公众号 [彭旭锐] 提问。** - [LeetCode 单周赛第 345 场 · 体验一题多解的算法之美](https://mp.wei ......
c语言刷leetcode——二分搜索
https://leetcode.cn/problems/path-with-minimum-effort/solutions/1345046/er-fen-by-dvuszkq61y-6vr1/ ![image](https://img2023.cnblogs.com/blog/1569451/2 ......
leetcode724
使用数学方法: 假设左边的所有数加起来的和是sum,total为数组所有元素加起来的和,当i满足中心下标的条件时,即: sum=total-sum-nums[i]; 2*sum+nums[i]=total; 当中心下标是首位时,即左边sum为0;当中心下标是尾位时,右边total-sum-nums[ ......
AtCoder Regular Contest 130 E Increasing Minimum
这题太神仙了吧!感觉还不是很懂,但是尽力理一下思路。 设 $t_x$ 为最大的 $j$ 使得 $i_j = x$,不存在则 $t_x = 0$。 设 $1 \sim n$ 的数按照 $t$ 从小到大排序后是 $p_1, p_2, ..., p_n$,设 $q_i$ 为 $i$ 在 $p$ 中的排名, ......
leetcode1493
递归: 1.记pre[i]为以i位置结尾的连续1长度。 pre[i]=0;ai=0 pre[i]=pre[i-1]+1;ai=1 记suf[i]为以位置i开头的连续1长度; suf[i]=0;ai=0 suf[i]=suf[i+1]+1;ai=1 计算删掉i位置的连续1的长度为pre[i-1]+su ......
leetcode 23. 合并 K 个升序链表
题目链接:https://leetcode.cn/problems/merge-k-sorted-lists/ 第一种写法,不断将未排序的链表插入到一个已经排序的链表中。 这样写的问题在于,当未排序的链表逐渐变的很大时,每插入一个新链表,都会来一次O(kn),总时间复杂度为O(k²n) 我们可以通过 ......