LeetCode刷题
刷力扣算法题
右京先生
我这个人很懒,什么都没有写
展开
-
LeetCode-07-88合并两个有序数组
把nums2位置上的挪到nums1中,在sort排序,没啥好说的。class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { for (int i = 0; i != n; ++i) { nums1[m + i] = nums2[i]; } Arrays.sort(nums1); }}...原创 2021-11-10 10:34:28 · 134 阅读 · 0 评论 -
LeetCode-06-1两数之和
class Solution { public int[] twoSum(int[] nums, int target) { //设计一个hashmap Map<Integer,Integer> map = new HashMap<Integer,Integer>(); int n = nums.length; //循环遍历数组 for(int i = 0;i < n;++i) { .原创 2021-11-10 10:13:57 · 115 阅读 · 0 评论 -
LeetCode-05-53最大子序和
class Solution { public int maxSubArray(int[] nums) { int max = nums[0]; int tem = 0; for(int i = 0;i < nums.length;i++) { tem = Math.max(nums[i] + tem,nums[i]); max = Math.max(max,tem); } .转载 2021-11-09 10:11:40 · 113 阅读 · 0 评论 -
LeetCode-04-217存在重复元素
class Solution { public boolean containsDuplicate(int[] nums) { Set<Integer> set = new HashSet<>(); for(int num : nums) { if(set.contains(num)) return true; set.add(num); } .原创 2021-11-09 09:26:22 · 89 阅读 · 0 评论 -
LeetCode-03-299猜数字游戏
刚开始没看懂题,看了宫水老师的解题才明白是什么意思。1.首先查看两串中位置一样的,那么这样就是毋庸置疑的公牛。比如 1807 7810 这两串中,8都是第二个,那么这个8就是公牛2.然后再计算可以交换位置的,所谓可以交换位置,就是说secret有这个数字,guess也有这个数字,但是两者位置不一样3.把secret和guess中相同坐标不同的数字,放进一个数组中(类似桶排序的过程)哈希,计数arr1[0] = 1 arr1[1] = 1 arr1[7]=1arr2[0] = 1 arr.原创 2021-11-08 10:04:13 · 2672 阅读 · 0 评论 -
LeetCode_MySQL11_1179.重新格式化部门表
无聊啊SELECT d.id as id, MIN(CASE month WHEN 'Jan' THEN revenue ELSE NULL END) AS Jan_Revenue, MIN(CASE month WHEN 'Feb' THEN revenue ELSE NULL END) AS Feb_Revenue, MIN(CASE month WHEN 'Mar' THEN revenue ELSE NULL END) AS Mar_Revenue, M.原创 2021-05-31 18:59:01 · 47 阅读 · 0 评论 -
LeetCode_MySQL10_627变更性别
判断,三元运算update salary set sex = if(sex="m","f","m");原创 2021-05-31 16:44:49 · 58 阅读 · 0 评论 -
LeetCode_MySQL09_596超过5名学生的课
select class from courses group by class having count(DISTINCT student) >= 5;原创 2021-05-25 16:17:51 · 55 阅读 · 0 评论 -
LeetCode_MySQL08_595大的国家
没啥好说的SELECT name, population, areaFROM worldWHERE area > 3000000 OR population > 25000000;原创 2021-05-25 14:13:38 · 51 阅读 · 0 评论 -
LeetCode_MySQL07_197上升的温度
没啥好说的根据条件筛选信息。select a.id from weather as a join weather as b on DATEDIFF(a.recordDate, b.recordDate ) = 1 and a.Temperature>b.Temperature;原创 2021-05-24 18:57:39 · 56 阅读 · 0 评论 -
LeetCode_MySQL06_196删除重复的电子邮箱
自连接delete a from person as a join person as bwhere a.email = b.email and a.id > b.id原创 2021-05-24 12:32:55 · 63 阅读 · 0 评论 -
LeetCode_MySQL05_183从不订购的客户
查询Orders表中的CustomerId,再查Customers表中的ID不在这些CustomerId中的,注意查询Orders表不要查找名字,因为表Customers中ID不可以重复,但名字不一定,大意了,第一次提交出错了。select Name Customers from Customerswhere Id not in (select CustomerId from Orders);...原创 2021-05-20 13:35:26 · 68 阅读 · 0 评论 -
LeetCode_MySQL04_182重复的电子邮件
按照电子邮件的名称分组,统计每一组的个数,揪出大于1就可以得出重复的电子邮件了。select Email from Person group by Email having count(*) > 1;原创 2021-05-20 09:26:48 · 69 阅读 · 0 评论 -
LeetCode_MySQL03_181超过经理收入的员工
内连接,将Employee表作为a b两个表.a负责处理普通员工表,b负责处理经理表。查询a的经理 a.ManagerId b的员工号 b.Ida.ManagerId = b.Ida的薪水大于b的薪水。select a.name as Employee from Employee a join Employee b on a.ManagerId=b.id and a.salary > b.salary;...原创 2021-05-19 16:06:37 · 67 阅读 · 0 评论 -
LeetCode_MySQL02_176第二高的薪水
这一题比较简单,先查询出最高的薪水,然后子查询小于最高薪水的薪水。SELECT Max(Salary) AS 'SecondHighestSalary' from Employee where Salary < (SELECT Max(Salary) from Employee);原创 2021-05-18 09:11:13 · 70 阅读 · 0 评论 -
LeetCode_MySQL01_175组合两个表
第一题很简单就不写注释了,左连接select Person.FirstName, Person.LastName, Address.City, Address.Statefrom Person left join Addresson Person.PersonId = Address.PersonId;原创 2021-05-17 11:06:30 · 55 阅读 · 0 评论 -
LeetCode-02-80删除排序数组中的重复项
title: LeetCode_02_80删除排序数组中的重复项- 双指针LeetCode_80删除排序数组中的重复项给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度。不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。示例 1:给定 nums = [1,1,1,2,2,3],函数应返回新长度 length = 5, 并且原数组的前五个元素被修改为 1, 1, 2, 2, 3 。你不需要考虑数组中.原创 2021-05-07 11:43:01 · 58 阅读 · 0 评论 -
LeetCode-01-26删除排序数组中的重复项
title: LeetCode_01_26删除排序数组中的重复项- 双指针LeetCode_26删除排序数组中的重复项给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。示例 1:给定数组 nums = [1,1,2],函数应该返回新的长度 2, 并且原数组 nums 的前两个元素被修改为 1, 2。你不需要考虑数组中超出新长度后面的元素。示例 2.原创 2021-05-07 11:41:58 · 55 阅读 · 0 评论