倍数leetcode multiple largest

LeetCode 周赛 340,质数 / 前缀和 / 极大化最小值 / 最短路 / 平衡二叉树

本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问。 大家好,我是小彭。 上周跟大家讲到小彭文章风格的问题,和一些朋友聊过以后,至少在算法题解方面确定了小彭的风格。虽然竞赛算法题的文章受众非常小,但却有很多像我一样的初学者,他们有兴趣参加但容易被题目难度和大神选 ......
质数 前缀 LeetCode 340

LeetCode习题——有效的完全平方数(二分查找)

有效的完全平方数 力扣链接:367. 有效的完全平方数 题目 给你一个正整数 num 。如果 num 是一个完全平方数,则返回 true ,否则返回 false 。 完全平方数是一个可以写成某个整数的平方的整数。换句话说,它可以写成某个整数和自身的乘积。 不能使用任何内置的库函数,如 sqrt 。 ......
习题 LeetCode

[LeetCode] 1440. Jump Game V 跳跃游戏之五

Given an array of integers arr and an integer d. In one step you can jump from index i to index: i + x where: i + x < arr.length and 0 < x <= d. i - x ......
LeetCode 1440 Jump Game

【前缀和】LeetCode 1031. 两个非重叠子数组的最大和

题目链接 1031. 两个非重叠子数组的最大和 思路 代码 class Solution { public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) { // 求一个前缀和 for(int i = 1; i < n ......
前缀 数组 LeetCode 两个 1031

【前缀和】LeetCode 1423. 可获得的最大点数

题目链接 1423. 可获得的最大点数 思路 通过逆向思维来考虑,因为我们是从两头拿数字,所以最终剩下的数字一定是位于中间的连续子数组。 因为数组总和不变,所以求两边数字加和的最大值,实际上就是求中间数字加和的最小值 代码 class Solution { public int maxScore(i ......
前缀 点数 LeetCode 1423

【DP】【分治】LeetCode 53. 最大子数组和

题目链接 [https://leetcode.cn/problems/maximum-subarray/description/](53. 最大子数组和 "https://leetcode.cn/problems/maximum-subarray/description/") 思路 分析动态规划题目 ......
数组 LeetCode 53

剑指 Offer 09. 用两个栈实现队列 && leetcode225.用队列实现栈

剑指 Offer 09. 用两个栈实现队列 class CQueue { private: stack<int> inStack, outStack; void in2out(){ //这里必须是while循环,如果是if判断,则输出栈日常只有一个值,没有起到先入后出的作用 while(!inSta ......
队列 amp leetcode 两个 Offer

LeetCode 109 有序链表转换二叉树

LeetCode 109.有序链表转换二叉搜索树 给定一个单链表的头节点 head ,其中的元素 按升序排序 ,将其转换为高度平衡的二叉搜索树。 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差不超过 1。 示例 1: 输入: head = [-10,-3,0,5,9] 输出 ......
LeetCode 109

leetcode_打卡3

leetcode_打卡3 题目:1431. 拥有最多糖果的孩子 解答: class Solution { public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) { int max=0; int n=candies. ......
leetcode

leetcode_打卡2

leetcode_打卡2 1071. 字符串的最大公因子 思路: 该题的答案一定是两个字符串的公共前缀,找到最大公共前缀,并且验证这个前缀能否被两个字符串除尽! class Solution { public String gcdOfStrings(String str1, String str2) ......
leetcode

【扫描线】LeetCode 218. 天际线问题

题目链接 218. 天际线问题 思路 参考宫水三叶大佬题解 代码 class Solution { public List<List<Integer>> getSkyline(int[][] buildings) { List<List<Integer>> result = new ArrayLis ......
扫描线 天际线 天际 LeetCode 问题

回溯理论基础及leetcode

#回溯 与递归相辅相成;回溯是递归的副产品,只要有递归就会有回溯。 回溯函数也就是递归函数,指的都是一个函数。 ##回溯搜索法 纯暴力搜索 解决的问题 组合问题:N个数里面按一定规则找出k个数的集合 切割问题:一个字符串按一定规则有几种切割方式 子集问题:一个N个数的集合里有多少符合条件的子集 排列 ......
leetcode 理论 基础

Leetcode 2. 两数相加

这道题让我想起了acwing里的高精度加法,因为这里的加法也是超过100位了。于是套着模板写了一下,然后看了一下评论区,发现链表再套vector属于是脱裤子放屁了 /** * Definition for singly-linked list. * struct ListNode { * int v ......
Leetcode

[C++]LeetCode1147. 段式回文

[C++]LeetCode1147. 段式回文 题目描述 Difficulty: 困难 Related Topics: 贪心, 双指针, 字符串, 动态规划, 哈希函数, 滚动哈希 你会得到一个字符串 text 。你应该把它分成 k 个子字符串 (subtext1, subtext2,…, subt ......
回文 段式 LeetCode 1147

leetcode 197 上升的温度

上升的温度 date_add(interval expr type) 使用日期相加函数 select w1.id from Weather w1 left join Weather w2 on w1.recordDate = date_add(w2.recordDate, interval 1 da ......
leetcode 温度 197

leetcode 196 删除重复的电子邮箱

删除重复的电子邮箱 mysql 来说,inner join 是在做笛卡尔积 delete p1 from Person p1 inner join Person p2 on p1.email = p2.email and p1.Id > p2.Id delete p1 FROM person p1 ......
电子邮箱 leetcode 邮箱 电子 196

LeetCode 91. 解码方法

class Solution { public: int f[110]; bool check(char a,char b) { if(a>='1'&&a<='9'&&b>='0'&&b<='9') { int c=a-'0'; c=c*10+(b-'0'); if(c>=1&&c<=26) ret ......
LeetCode 方法 91

LeetCode #453 最小操作次数使数组元素相等

基本思路 每次让数组的n-1个元素加1——等价于——每次让一个元素减1; 把所有数加到相同的最大值 ——等价于——把所有的数捡到最小值; 因此最小操作次数 = 数组所有元素之和 - ( 数组长度 * 最小值); 标程 1 class Solution { 2 public: 3 int minMov ......
数组 LeetCode 元素 次数 453

leetcode 185

部门工资前三高的所有员工 select d.name as Department, e.name as Employee, e.salary as Salary from Employee e left join Department d on e.departmentId = d.Id where ......
leetcode 185

LeetCode #448 找到所有数组中消失的数字

基本思路 为了满足题目要求的不使用额外的存储空间(当然返回的数组除外),并且时间复杂度控制在O(n),最多只能常数级别遍历,因此考虑将原数组视作一个"哈希表"。 遍历原数组,将【1,n】上的值域映射到【0,n-】的坐标上,某个数x扫描到一次则将这个数x映射的 x-1的坐标处的值加上n。 然后再次遍历 ......
数组 LeetCode 数字 448

LeetCode #283 移动零(双指针版本,效率高)

基本思路 思路————双指针 初始状态左右指针都指向数组首位元素,然后right指针开始迭代数组,当碰到非0元素则与左指针left所在位置的元素交换。 交换完毕后,左指针left则向前移动到下一位置,做好准备迎接下一个非0元素的交换。 这种算法效率比之前撰写的“伪双指针”效率更高,更能应对特殊情况。 ......
指针 LeetCode 效率 版本 283

LeetCode #645 错误的集合

基本思路 用一个vector来模拟哈希表,记录每个元素的数量从而来找到重复的数和缺失的数。 标程 1 class Solution { 2 public: 3 vector<int> findErrorNums(vector<int>& nums) { 4 int n = nums.size(); ......
LeetCode 错误 645

LeetCode #697 数组的度

基本思路 需要知道数组中某些元素的出现次数来寻求最大出现次数,以及要找到长度最短的子数组长度。 因此可以考虑使用哈希表来记录某个元素出现的次数,第一个元素出现的下表,最后一个元素出现的下标。映射关系:x-->{times,starti,endj}。 标程 1 class Solution { 2 p ......
数组 LeetCode 697

LeetCode #414 第三大的数

解题思路数组从大到小排序后,从第2个元素开始遍历,如果与上一个元素不相同,则标志位++,标志位一旦从1加到3(两次)则代表存在第三大的数,即可返回。如若不存在第三大的数,则在遍历结束后,函数末尾返回数组的第一个元素(最大的元素)。 标程 1 class Solution { 2 public: 3 ......
LeetCode 三大 414

LeetCode #485 最大连续 1 的个数

解题思路基础题,最后加一个特殊情况处理就好,时间复杂度O(n) 代码 class Solution {public: int findMaxConsecutiveOnes(vector<int>& nums) { int count=0; int Maxcount=0; for(int i =0; ......
个数 LeetCode 485

4月11日leetcode练习

设计一个支持 push ,pop ,top 操作,并能在常数时间内检索到最小元素的栈。 实现 MinStack 类: MinStack() 初始化堆栈对象。void push(int val) 将元素val推入堆栈。void pop() 删除堆栈顶部的元素。int top() 获取堆栈顶部的元素。i ......
leetcode

leetcode 184

部门工资最高的员工 select d.name as Department, e.name as Employee, e.salary as Salary from Employee e left join Department d on e.departmentId = d.id where (e ......
leetcode 184

leetcode 183

从不订购的客户 select c.Name as Customers from Customers c left join Orders o on c.Id = o.CustomerId where o.CustomerId is null select customers.name custome ......
leetcode 183

leetcode 182

查找重复的电子邮箱 select email as Email from Person group by email having count(email) > 1 select email as Email from ( select email ,count(email) as c from P ......
leetcode 182

leetcode 181

超过经理收入的员工 select e1.name as Employee from Employee e1, Employee e2 where e1.managerId = e2.id and e1.salary > e2.salary select e1.name as Employee fro ......
leetcode 181