之和leetcode 3sum sum

[刷题班] LeetCode442. 数组中重复的数据

题目描述 思路 原地哈希: 利用值域与数组下标空间大小的等同关系,我们可以构造一种对应"关系" 找到数字i时,将位置i-1处的数字翻转为负数 如果位置i-1上的数组已经为负数,则i是出现两次的数字,并将其加入到结果集中 方法一: class Solution { public List<Intege ......
数组 LeetCode 数据 442

[LeetCode] 1979. Find Greatest Common Divisor of Array

Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums. The greatest common divisor of two ......
LeetCode Greatest Divisor Common Array

[LeetCode] 2807. Insert Greatest Common Divisors in Linked List

Given the head of a linked list head, in which each node contains an integer value. Between every pair of adjacent nodes, insert a new node with a val ......
LeetCode Greatest Divisors Insert Common

leetcode 4. 寻找两个正序数组的中位数

leetcode 4. 寻找两个正序数组的中位数 第四题:寻找两个正序数组的中位数 1.合并数组,排序,找中位数 ​ 暴力解法,时间复杂度(M+N),空间复杂度(M+N) public double findMedianSortedArrays(int[] nums1, int[] nums2) { ......
中位数 数组 leetcode 两个

15、三数之和

//三数之和 #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; vector<vector<int>> threeSum(vector<int>& nums) { ......
之和

16、最接近的三数之和

//最接近的三数之和 #include<iostream> #include<string> #include<vector> #include<cmath> #include<algorithm> using namespace std; //双指针 int threeSumClosest(vec ......
之和

分治法LeetCode经典例题(c语言解法)

多数元素https://leetcode.cn/problems/majority-element/description/ `//计数 int count(int* nums,int target,int left,int right){ int cnt = 0; for(int i = left ......
解法 例题 LeetCode 语言 经典

CF1270G Subset with Zero Sum

G. Subset with Zero Sum 很妙。 一开始冲着背包去想的,显然不行。 考虑他条件给的这个 \(i − n \le a_i \le i − 1\) 化简一下得到 \[1 \le i - a_i \le n \]题目要去求 \[\sum \limits_{i \in S} a_i = ......
Subset 1270G 1270 with Zero

[ARC150F] Constant Sum Subsequence

更好的阅读体验 [ARC150F] Constant Sum Subsequence 很有意思的题。 设 \(nex_{i,j}\) 表示位置 \(i\) 后面的最小的满足 \(k>i\wedge a_k=j\) 的 \(k\),则问题可以抽象为: \[f_i=\max_{j=1}^inex_{f_ ......
Subsequence Constant 150F ARC 150

CF1270G Subset with Zero Sum

题目链接:洛谷 或者 CF 比较朴素的题,首先观察题目条件: \[ i-n \le a_i \le i-1 \Rightarrow 1 \le i-a_i \le n \text{,所以易知 } i-a_i \text{ 必定是某一点} \]考虑构造题目所说 \[\sum_{i=x_1}^{x_{t ......
Subset 1270G 1270 with Zero

day07 代码随想录算法训练营 15. 三数之和

题目:15. 三数之和 我的感悟: 加油,我可以的。不能放弃。 理解难点: 双指针 思路打开 边界考虑 代码难点: 缩进问题 continue是跳出循环条件 我以前分不清循环条件和判断条件。哈哈哈。一个是if 一个是while / for 总结概括: 只要不放弃就行!!!!!!!! 代码示例: cl ......
随想录 之和 训练营 随想 算法

Leetcode 2982. 找出出现至少三次的最长特殊子字符串 II

开26个multiset,对于aabaaa,遍历,对第0个multiset push 1 2,然后对第一个multiset push 1,然后又对第0个multiset push 1 2,这时第0个multiset size超过3了,删除最小的元素,然后继续push 3,最后取 \(max_{i=1 ......
字符串 字符 Leetcode 2982 II

使用Cookie在VS Code中登录LeetCode插件

在VS Code的LeetCode插件中使用Cookie登录 1 在浏览器中打开leetcode网页并登录进去 2 按F12查看网页元素,找到graphql,查看其中的cookie,复制该cookie 3 在VS Code中点击登录leetcode的按钮,在登录方式中选择使用cookie登录,然后将 ......
插件 LeetCode Cookie Code

超微X12主板通过sum升级出现OEM参数支持的问题

出现以下情况,请更新你的sum工具,超微X11主板和X12主板OEM定制参数发生了改变,所以出现了不支持的OEM参数 ......
主板 参数 问题 X12 OEM

代码随想录 day07 四数相加 赎金信 三数之和 四数之和

四数相加 题目需要找满足和为0的四元组 但是只要求统计个数 不要求具体的四元组 而且四元组是可以重复的 考虑使用hash map 由于设计到四个元素 先遍历两个集合 记录一下两个集合的元素和的所有可能值 记录在map中 为什么要用map 因为需要同时记录出现的值和出现的次数 值作为键 次数作为值 然 ......
之和 随想录 随想 代码 day

CF1442D Sum

题意 给定 \(n\) 个递增数组。 \(k\) 次操作,每次你可以选择一个数组,使 \(ans\) 加上数组的第一个数,并删除。 问最大化的 \(ans\) 的值。 Sol 考虑当前选择的方案如何变得更优。 不难想到,如果当前有两个数组没有选满,则一定可以调整到其中一个变成空的方案,而使得答案不劣 ......
1442D 1442 Sum CF

day06 代码随想录算法训练营 1. 两数之和

题目:1. 两数之和 我的感悟: 梦开始的地方 理解难点: map究竟是什么 存放已经遍历的元素值 什么时候需要用map? 遍历一边,这里面的元素值,后面都有可能要用就存起来。 代码难点: 掌握enumerate用法 [ɪ'njuːməreɪt] e + numer + ate 助记: e-出 + ......
随想录 之和 训练营 随想 算法

代码随想录 day06 有效的字母异位词 返回数组的交集 找快乐数 两数之和

有效的字母异位词: 思路比较简单 由于范围比较小 只有小写字母为范围 利用26大小的数组 遍历字符串 第一个串在对应下标++ 第二个++ 然后数据存在不为零就是不一样的 不存在则时字母异位词 返回数组的交集 由于要返回的是交集 就是查找两个集合出现的元素 想到要使用hash map 具体的数据结构而 ......
随想录 之和 数组 交集 随想

leetcode 3.无重复字符的最长子串

leetcode 第三题:无重复字符的最长子串 自己写的: 第一想法:滑动窗口,用两个指针指向窗口的左右边界,用一个HashSet存储窗口内已有的值。另写一个find_first_temp方法用于出现重复字符时寻找新的左边界,左边界更新时也要更新set,将新左边界之前的元素删掉。 public in ......
字符 leetcode

P10033 「Cfz Round 3」Sum of Permutation

原题链接 基础赛唯一写了的题,因为我喜欢构造! 事实上的确有点麻烦了,应该会有更好的做法。但是自我感觉这个思维很连贯,因为这就是我做题时思路的写照。 记 \(p_{pos1}=1,p_{posn}=n\)。 首先可以构造 \(a_i\gets p_i+1\) 这样一定满足第二个限制,但是当 \(p_ ......
Permutation P10033 10033 Round Cfz

leetcode 2.两数相加

leetcode 第二题:两数相加 以链表为载体模仿加法进位,同时遍历两个链表,逐位计算它们的和,并与当前位置的进位值相加。如果两个链表的长度不同,则可以认为长度短的链表的后面有若干个 0 。如果链表遍历结束后,有 carry>0,还需要在答案链表的后面附加一个节点,节点的值为 carry。 易错点 ......
leetcode

leetcode 1.两数之和

leetcode 第一题:两数之和 1.暴力枚举: 最容易想到的方法是枚举数组中的每一个数 x,寻找数组中是否存在 target - x。 当我们使用遍历整个数组的方式寻找 target - x 时,需要注意到每一个位于 x 之前的元素都已经和 x 匹配过,因此不需要再进行匹配。而每一个元素不能被使 ......
之和 leetcode

代码随想录算法训练营第十七天 | 110.平衡二叉树,257. 二叉树的所有路径,404.左叶子之和

一、110.平衡二叉树 题目链接: LeetCode 110.平衡二叉树 学习: 思路: 后序遍历。实际上是由叶结点到根结点,若有一颗子树不是平衡二叉树,则直接返回给根结点 二、257.二叉树的所有路径 题目链接: LeetCode 257.二叉树的所有路径 学习: 思路: 递归+回溯。因为是线=先 ......
随想录 之和 训练营 随想 算法

leetcode 2706 购买两块巧克力

题目: 2706 购买两块巧克力 思路: 找两个最小值。 分情况讨论 代码 class Solution: def buyChoco(self, prices: List[int], money: int) -> int: # 遍历一遍,找2个最小值 # 找一个最小值我们都会。 # 找次小值,就分两 ......
巧克力 leetcode 2706

在不使用内置函数和中间变量的情况交换数字LeetCode力扣题解面试题16.01

#异或法#Kotlin ```Kotlinclass Solution { fun swapNumbers(numbers: IntArray): IntArray { numbers[0] = numbers[0] xor numbers[1] numbers[1] = numbers[1] xo ......
题解 变量 函数 LeetCode 情况

2023.12.28 leedcode 两数之和

class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): if target - nums[i] in nums[i + 1 :]: if i != ......
之和 leedcode 2023 12 28

[LeetCode] 1578. Minimum Time to Make Rope Colorful

Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon. Alice wants the rope ......
LeetCode Colorful Minimum 1578 Make

[LeetCode Hot 100] LeetCode111. 二叉树的最小深度

题目描述 思路 二叉树的最小深度就是第一个叶子节点所在的层数 方法一:前序遍历(递归、dfs) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeN ......
LeetCode 深度 Hot 100 111

[LeetCode Hot 100] LeetCode110. 平衡二叉树

题目描述 思路 LeetCode104. 二叉树的最大深度 变种 方法一:后序遍历(递归、dfs) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tre ......
LeetCode Hot 100 110

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

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