leetcode minimum arrive speed

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

【LeetCode回溯算法#extra01】集合划分问题【火柴拼正方形、划分k个相等子集、公平发饼干】

火柴拼正方形 https://leetcode.cn/problems/matchsticks-to-square/ 你将得到一个整数数组 matchsticks ,其中 matchsticks[i] 是第 i 个火柴棒的长度。你要用 所有的火柴棍 拼成一个正方形。你 不能折断 任何一根火柴棒,但你 ......
子集 正方形 正方 饼干 火柴

[LeetCode] 2390. Removing Stars From a String

You are given a string s, which contains stars *. In one operation, you can: Choose a star in s. Remove the closest non-star character to its left, as ......
LeetCode Removing String Stars 2390

leetcode 180

连续出现的数字 select distinct l1.num as ConsecutiveNums from Logs l1, Logs l2, Logs l3 where l1.id = l2.id - 1 and l2.id = l3.id - 1 and l1.num = l2.num and ......
leetcode 180

leetcode_打卡1

leetcode_打卡1 题目:1768. 交替合并字符串 解答: 思路: 模拟即可,字符串的提取: a.charAt(i) class Solution { public String mergeAlternately(String word1, String word2) { String re ......
leetcode

leetcode 178

分数排名 select s1.score, count(distinct s2.score) as `rank` from Scores as s1, Scores as s2 where s1.score <= s2.score group by s1.id order by s1.score d ......
leetcode 178

leetcode 177

第N高的薪水 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN declare T int default 0; SET T = N-1; RETURN ( # Write your MySQL query statement ......
leetcode 177

LeetCode 959. 有斜杠划分区域

题目: https://leetcode.cn/problems/regions-cut-by-slashes/description/ 题解(参考了讨论区):将初始N*N的网格看做4 * N* N的三角形集合,根据输入合并对应的三角形。 C# 实现 public class Solution { ......
斜杠 LeetCode 区域 959

Leetcode(剑指offer专项训练)——DFS/BFS专项(3)

重建序列 题目 给定一个长度为 n 的整数数组 nums ,其中 nums 是范围为 [1,n] 的整数的排列。还提供了一个 2D 整数数组 sequences ,其中 sequences[i] 是 nums 的子序列。 检查 nums 是否是唯一的最短 超序列 。最短 超序列 是 长度最短 的序列 ......
专项 Leetcode offer DFS BFS

LeetCode习题——x 的平方根(二分查找)

### x 的平方根 力扣链接:[x 的平方根 ](https://leetcode.cn/problems/sqrtx/) #### 题目 > 给你一个非负整数 x ,计算并返回 x 的 算术平方根 。>> 由于返回类型是整数,结果只保留 整数部分 ,小数部分将被 舍去 。>> 注意:不允许使用任 ......
平方根 习题 LeetCode