Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe3169e

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

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 globimport glob
4+
dirs= os.listdir('/Users/lixiang.2533/Desktop/Blogs/Leetcode/')
5+
dir='/Users/lixiang.2533/Desktop/Blogs/Leetcode'
6+
dirs= ['哈希表','','二分法','数学题','链表','字符串','数组','']
7+
for ain 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 iin md_list]
12+
file_name=dict([(i.split('.')[0], i)for iin file_name])
13+
## 给总结md加入title
14+
withopen(md_list[0],'r')as f:
15+
lines= f.readlines()
16+
new_lines= []
17+
for iin 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+
withopen(md_list[0],'w')as f:
26+
f.writelines(new_lines)
27+
for mdin md_list:
28+
md_name= md.split('/')[-1]
29+
contents.append('###'+ md_name+"\n")
30+
withopen(md,'r')as f:
31+
contents.append(f.read()+"\n")
32+
33+
withopen(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+
selectP.FirstName,P.LastName,A.City,A.State
37+
from Person p
38+
left join Address AonP.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+
selecte2.Nameas Employee
30+
from Employee e1
31+
left join Employee e2one2.ManagerId=e1.Id
32+
wheree1.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+
havingcount(1)>1
48+
```
49+

‎mysql/183. 从不订购的客户.md

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+
selectc.Nameas Customers
37+
from Customers c
38+
left join Orders oonc.Id=o.CustomerId
39+
whereo.CustomerId isnull
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+
| 1|john@example.com|
7+
| 2|bob@example.com|
8+
| 3|john@example.com|
9+
+----+------------------+
10+
Id 是这个表的主键。
11+
12+
例如,在运行你的查询语句之后,上面的 Person 表应返回以下几行:
13+
14+
+----+------------------+
15+
| Id| Email|
16+
+----+------------------+
17+
| 1|john@example.com|
18+
| 2|bob@example.com|
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 p1from Person p1, Person p2
33+
where p1.Email= p2.Emailand 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+
selectw1.id
44+
from weather w1, weather w2
45+
where datediff(w1.recordDate,w2.recordDate)=1
46+
andw1.Temperature>w2.Temperature
47+
```
48+

‎二分法/.DS_Store

6 KB
Binary file not shown.

‎二分法/0.二分法总结.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- 找target
2+
- 33 搜索旋转排序数组
3+
- 74 搜索二维矩阵
4+
- 367 有效的完全平方数
5+
- 374 猜数字大小
6+
- 704 二分查找
7+
- 找边界
8+
- 34 在排序数组中查找元素的第一个和最后一个位置
9+
- 35 搜索插入位置
10+
- 278 第一个错误的版本
11+
- 441 排列硬币
12+
- 牛顿法
13+
- 69 x 的平方根
14+
- 367 有效的完全平方数
15+
- divide
16+
- 29 两数相除
17+
- 50 Pow(x, n)
18+
- 有技巧的二分法
19+
- 81 搜索旋转排序数组 II
20+
- 153 寻找旋转排序数组中的最小值
21+
- 162 寻找峰值
22+
- 240 搜索二维矩阵 II
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
已知一个长度为 n 的数组,预先按照升序排列,经由 1 到 n 次 旋转 后,得到输入数组。例如,原数组 nums =[0,1,2,4,5,6,7] 在变化后可能得到:
2+
3+
若旋转 4 次,则可以得到 [4,5,6,7,0,1,2]
4+
若旋转 7 次,则可以得到 [0,1,2,4,5,6,7]
5+
6+
注意,数组[a[0], a[1], a[2], ..., a[n-1]] 旋转一次 的结果为数组[a[n-1], a[0], a[1], a[2], ..., a[n-2]]
7+
8+
给你一个元素值 互不相同 的数组 nums ,它原来是一个升序排列的数组,并按上述情形进行了多次旋转。请你找出并返回数组中的 最小元素 。
9+
10+
11+
12+
示例 1:
13+
14+
输入:nums =[3,4,5,1,2]
15+
输出:1
16+
解释:原数组为[1,2,3,4,5] ,旋转 3 次得到输入数组。
17+
18+
示例 2:
19+
20+
输入:nums =[4,5,6,7,0,1,2]
21+
输出:0
22+
解释:原数组为[0,1,2,4,5,6,7] ,旋转 4 次得到输入数组。
23+
24+
示例 3:
25+
26+
输入:nums =[11,13,15,17]
27+
输出:11
28+
解释:原数组为[11,13,15,17] ,旋转 4 次得到输入数组。
29+
30+
31+
32+
提示:
33+
34+
n == nums.length
35+
1 <= n <= 5000
36+
-5000 <= nums[i] <= 5000
37+
nums 中的所有整数 互不相同
38+
nums 原来是一个升序排序的数组,并进行了 1 至 n 次旋转
39+
40+
41+
42+
```python
43+
classSolution:
44+
deffindMin(self,nums: List[int]) ->int:
45+
n=len(nums)
46+
start=0
47+
end= n-1
48+
while start< end:
49+
mid= (start+end)//2
50+
if nums[mid]> nums[end]:
51+
start= mid+1
52+
else:
53+
end= mid
54+
return nums[start]
55+
```
56+
57+
58+
59+
Tips
60+
61+
注意这里左右边界不对称只能和右边界比较,因为

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp