Skip to content

Commit be3169e

Browse files
author
lixiang.2533
committed
first commit
Change-Id: I947fb5f9d371c046f3893da2067ca107fad15f0a
0 parents  commit be3169e

File tree

374 files changed

+46021
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

374 files changed

+46021
-0
lines changed

.DS_Store

14 KB
Binary file not shown.

.md

Whitespace-only changes.

merge_md.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```python
2+
import os
3+
from glob import glob
4+
dirs = os.listdir('/Users/lixiang.2533/Desktop/Blogs/Leetcode/')
5+
dir = '/Users/lixiang.2533/Desktop/Blogs/Leetcode'
6+
dirs = ['哈希表', '', '二分法', '数学题', '链表','字符串', '数组', '']
7+
for a in dirs:
8+
md_list = glob(os.path.join(dir, a,'*.md'))
9+
md_list = sorted(md_list)
10+
contents = []
11+
file_name = [i.split('/')[-1].split('.md')[0] for i in md_list]
12+
file_name = dict([(i.split('.')[0], i) for i in file_name])
13+
## 给总结md加入title
14+
with open(md_list[0],'r') as f:
15+
lines = f.readlines()
16+
new_lines = []
17+
for i in lines:
18+
if i.strip():
19+
nums = i.split('- ')[1]
20+
if nums.isdigit():
21+
new_lines.append(' - ' + file_name.get(nums, nums) + '\n')
22+
else:
23+
new_lines.append('- ' + file_name.get(nums, nums) + '\n')
24+
25+
with open(md_list[0], 'w') as f:
26+
f.writelines(new_lines)
27+
for md in md_list:
28+
md_name = md.split('/')[-1]
29+
contents.append('### ' + md_name + "\n")
30+
with open(md, 'r') as f:
31+
contents.append(f.read() + "\n")
32+
33+
with open(os.path.join(dir, "{}总结.md".format(a)), "w") as f:
34+
f.writelines(contents)
35+
```
36+
37+
38+
39+
1. 总结文档里填充名字
40+

mysql/175. 组合两个表.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
表1: Person
2+
3+
+-------------+---------+
4+
| 列名 | 类型 |
5+
+-------------+---------+
6+
| PersonId | int |
7+
| FirstName | varchar |
8+
| LastName | varchar |
9+
+-------------+---------+
10+
PersonId 是上表主键
11+
12+
表2: Address
13+
14+
+-------------+---------+
15+
| 列名 | 类型 |
16+
+-------------+---------+
17+
| AddressId | int |
18+
| PersonId | int |
19+
| City | varchar |
20+
| State | varchar |
21+
+-------------+---------+
22+
AddressId 是上表主键
23+
24+
25+
26+
编写一个 SQL 查询,满足条件:无论 person 是否有地址信息,都需要基于上述两表提供 person 的以下信息:
27+
28+
29+
30+
FirstName, LastName, City, State
31+
32+
33+
34+
```mysql
35+
# Write your MySQL query statement below
36+
select P.FirstName, P.LastName, A.City, A.State
37+
from Person p
38+
left join Address A on P.PersonId = A.PersonId
39+
```
40+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
SQL架构
2+
3+
`Employee` 表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。
4+
5+
```
6+
+----+-------+--------+-----------+
7+
| Id | Name | Salary | ManagerId |
8+
+----+-------+--------+-----------+
9+
| 1 | Joe | 70000 | 3 |
10+
| 2 | Henry | 80000 | 4 |
11+
| 3 | Sam | 60000 | NULL |
12+
| 4 | Max | 90000 | NULL |
13+
+----+-------+--------+-----------+
14+
```
15+
16+
给定 `Employee` 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。
17+
18+
```
19+
+----------+
20+
| Employee |
21+
+----------+
22+
| Joe |
23+
```
24+
25+
26+
27+
```mysql
28+
# Write your MySQL query statement below
29+
select e2.Name as Employee
30+
from Employee e1
31+
left join Employee e2 on e2.ManagerId = e1.Id
32+
where e1.Salary < e2.Salary
33+
```
34+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SQL架构
2+
3+
某网站包含两个表,`Customers` 表和 `Orders` 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
4+
5+
`Customers` 表:
6+
7+
```
8+
+----+-------+
9+
| Id | Name |
10+
+----+-------+
11+
| 1 | Joe |
12+
| 2 | Henry |
13+
| 3 | Sam |
14+
| 4 | Max |
15+
+----+-------+
16+
```
17+
18+
`Orders` 表:
19+
20+
```
21+
+----+------------+
22+
| Id | CustomerId |
23+
+----+------------+
24+
| 1 | 3 |
25+
| 2 | 1 |
26+
+----+------------+
27+
```
28+
29+
例如给定上述表格,你的查询应返回:
30+
31+
```
32+
+-----------+
33+
| Customers |
34+
+-----------+
35+
| Henry |
36+
| Max |
37+
+-----------+
38+
```
39+
40+
41+
42+
```mysql
43+
# Write your MySQL query statement below
44+
select Email
45+
from Person
46+
group by Email
47+
having count(1) >1
48+
```
49+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
2+
3+
Customers 表:
4+
5+
+----+-------+
6+
| Id | Name |
7+
+----+-------+
8+
| 1 | Joe |
9+
| 2 | Henry |
10+
| 3 | Sam |
11+
| 4 | Max |
12+
+----+-------+
13+
14+
Orders 表:
15+
16+
+----+------------+
17+
| Id | CustomerId |
18+
+----+------------+
19+
| 1 | 3 |
20+
| 2 | 1 |
21+
+----+------------+
22+
23+
例如给定上述表格,你的查询应返回:
24+
25+
+-----------+
26+
| Customers |
27+
+-----------+
28+
| Henry |
29+
| Max |
30+
+-----------+
31+
32+
33+
34+
```mysql
35+
# Write your MySQL query statement below
36+
select c.Name as Customers
37+
from Customers c
38+
left join Orders o on c.Id = o.CustomerId
39+
where o.CustomerId is null
40+
```
41+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。
2+
3+
+----+------------------+
4+
| Id | Email |
5+
+----+------------------+
6+
7+
8+
9+
+----+------------------+
10+
Id 是这个表的主键。
11+
12+
例如,在运行你的查询语句之后,上面的 Person 表应返回以下几行:
13+
14+
+----+------------------+
15+
| Id | Email |
16+
+----+------------------+
17+
18+
19+
+----+------------------+
20+
21+
22+
23+
提示:
24+
25+
执行 SQL 之后,输出是整个 Person 表。
26+
使用 delete 语句。
27+
28+
29+
30+
```python
31+
# Write your MySQL query statement belowd
32+
delete p1 from Person p1, Person p2
33+
where p1.Email = p2.Email and p1.Id>p2.Id
34+
```
35+
36+
37+
38+
Tips
39+
40+
1. 注意要删掉Id更大的row

mysql/197. 上升的温度.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
表 Weather
2+
3+
+---------------+---------+
4+
| Column Name | Type |
5+
+---------------+---------+
6+
| id | int |
7+
| recordDate | date |
8+
| temperature | int |
9+
+---------------+---------+
10+
id 是这个表的主键
11+
该表包含特定日期的温度信息
12+
13+
14+
15+
编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id 。
16+
17+
返回结果 不要求顺序 。
18+
19+
查询结果格式如下例:
20+
21+
Weather
22+
+----+------------+-------------+
23+
| id | recordDate | Temperature |
24+
+----+------------+-------------+
25+
| 1 | 2015-01-01 | 10 |
26+
| 2 | 2015-01-02 | 25 |
27+
| 3 | 2015-01-03 | 20 |
28+
| 4 | 2015-01-04 | 30 |
29+
+----+------------+-------------+
30+
31+
Result table:
32+
+----+
33+
| id |
34+
+----+
35+
| 2 |
36+
| 4 |
37+
+----+
38+
2015-01-02 的温度比前一天高(10 -> 25)
39+
2015-01-04 的温度比前一天高(20 -> 30)
40+
41+
```mysql
42+
# Write your MySQL query statement below
43+
select w1.id
44+
from weather w1, weather w2
45+
where datediff(w1.recordDate,w2.recordDate)=1
46+
and w1.Temperature > w2.Temperature
47+
```
48+

二分法/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)