【LeetCode】Problem List and Solutions

本文分享了LeetCode上精选算法题目的解题过程,包括链表操作、整数反转、字符串转换、DP应用及二分查找等,旨在帮助读者理解不同数据结构和算法的应用场景,提升解题能力。
ProblemKeyStar(s)DateAttention

2. Add Two Numbers

链表⭐⭐May 29,2019 
     
7. Reverse Integer May 27,2019取余和取模的区别

8. String to Integer

字符串、模拟⭐⭐May 27,2019 

15. 3Sum

二分查找⭐⭐⭐May 29,2019 

45. Jump Game II

DP⭐⭐⭐June 8,2019 

53. Maximum Subarray

DP⭐⭐Sep 28,2019最大字段和

120. Triangle

DP⭐⭐⭐May 28,2019 

169. Majority Element

 ⭐⭐May 29,2019擂台赛
240. Search a 2D Matrix II二分查找⭐⭐⭐  

392. Is Subsequence

字符串June 8,2019 

455. Assign Cookies

贪心⭐⭐June 8,2019 

To be continued……

第一次集中刷题:推免夏令营

### LeetCode MySQL Problems and Solutions #### Problem 1: Sales Analysis III Given three tables `Product`, `Sales` with the following structure: | Column Name | Type | |-------------|----------| | product_id | int | | product_name| varchar | | Column Name | Type | |-------------|----------| | seller_id | int | | product_id | int | | buyer_id | int | | sale_date | date | | quantity | int | | price | int | The task is to find products that were only sold in a specific year. ```sql SELECT DISTINCT p.product_id, p.product_name FROM Product AS p JOIN Sales AS s ON p.product_id = s.product_id WHERE YEAR(s.sale_date) = '2018' AND p.product_id NOT IN ( SELECT product_id FROM Sales WHERE YEAR(sale_date) != '2018') ``` This query selects distinct product IDs and names from the `Product` table where sales occurred exclusively in 2018 by filtering out any products sold outside this period[^1]. #### Problem 2: Big Countries A world table contains columns like name, continent, area, population, gdp. The goal is to list all countries larger than 3 million square kilometers or having more than 25 million people. ```sql SELECT name, population, area FROM world WHERE area > 3000000 OR population > 25000000; ``` This SQL statement retrieves country information based on specified size criteria using logical operators[^2]. #### Problem 3: Duplicate Emails With a Person table containing id and email fields, identify duplicate emails within it. ```sql SELECT Email , COUNT(*) as num FROM Person GROUP BY Email HAVING COUNT(*) > 1; ``` By grouping entries according to their email addresses and applying HAVING clause, one can easily spot duplicates[^3]. --related questions-- 1. How does JOIN operation work between two tables? 2. What are common aggregate functions used alongside GROUP BY statements? 3. Can you explain how subqueries function inside main queries? 4. In what scenarios should window functions be preferred over traditional aggregation methods?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值