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

Commit d967978

Browse files
committed
feat: add lc problems and solutions
1 parent 89544a4 commit d967978

File tree

14 files changed

+523
-36
lines changed

14 files changed

+523
-36
lines changed

‎solution/0600-0699/0633.Sum of Square Numbers/README.md‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@
4848
<li><code>0 &lt;= c &lt;= 2<sup>31</sup> - 1</code></li>
4949
</ul>
5050

51-
5251
## 解法
5352

5453
<!-- 这里可写通用的实现逻辑 -->
5554

56-
![](./images/table.png)
55+
![](https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/images/table.png)
5756

5857
上图为 a,b,c 之间的关系,这题其实就是在这张"表"里查找 c
5958

@@ -103,6 +102,43 @@ class Solution {
103102
}
104103
```
105104

105+
### **C++**
106+
107+
```cpp
108+
class Solution {
109+
public:
110+
bool judgeSquareSum(int c) {
111+
long i = 0, j = (long) sqrt(c);
112+
while (i <= j) {
113+
long s = i * i + j * j;
114+
if (s < c) ++i;
115+
else if (s > c) --j;
116+
else return true;
117+
}
118+
return false;
119+
}
120+
};
121+
```
122+
123+
### **Go**
124+
125+
```go
126+
func judgeSquareSum(c int) bool {
127+
i, j := 0, int(math.Sqrt(float64(c)))
128+
for i <= j {
129+
s := i*i + j*j
130+
if s < c {
131+
i++
132+
} else if s > c {
133+
j--
134+
} else {
135+
return true
136+
}
137+
}
138+
return false
139+
}
140+
```
141+
106142
### **...**
107143

108144
```

‎solution/0600-0699/0633.Sum of Square Numbers/README_EN.md‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@
5050
<li><code>0 &lt;= c &lt;= 2<sup>31</sup> - 1</code></li>
5151
</ul>
5252

53-
5453
## Solutions
5554

56-
![](./images/table.png)
55+
![](https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/images/table.png)
5756

5857
The picture above shows the relationship between `a`, `b`, and `c`. This question is actually looking up `c` in this table
5958

@@ -99,6 +98,43 @@ class Solution {
9998
}
10099
```
101100

101+
### **C++**
102+
103+
```cpp
104+
class Solution {
105+
public:
106+
bool judgeSquareSum(int c) {
107+
long i = 0, j = (long) sqrt(c);
108+
while (i <= j) {
109+
long s = i * i + j * j;
110+
if (s < c) ++i;
111+
else if (s > c) --j;
112+
else return true;
113+
}
114+
return false;
115+
}
116+
};
117+
```
118+
119+
### **Go**
120+
121+
```go
122+
func judgeSquareSum(c int) bool {
123+
i, j := 0, int(math.Sqrt(float64(c)))
124+
for i <= j {
125+
s := i*i + j*j
126+
if s < c {
127+
i++
128+
} else if s > c {
129+
j--
130+
} else {
131+
return true
132+
}
133+
}
134+
return false
135+
}
136+
```
137+
102138
### **...**
103139

104140
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
bool judgeSquareSum(int c) {
4+
long i = 0, j = (long) sqrt(c);
5+
while (i <= j) {
6+
long s = i * i + j * j;
7+
if (s < c) ++i;
8+
else if (s > c) --j;
9+
else return true;
10+
}
11+
return false;
12+
}
13+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func judgeSquareSum(c int) bool {
2+
i, j := 0, int(math.Sqrt(float64(c)))
3+
for i <= j {
4+
s := i*i + j*j
5+
if s < c {
6+
i++
7+
} else if s > c {
8+
j--
9+
} else {
10+
return true
11+
}
12+
}
13+
return false
14+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# [1204. 最后一个能进入电梯的人](https://leetcode-cn.com/problems/last-person-to-fit-in-the-bus)
2+
3+
[English Version](/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Bus/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>表: <code>Queue</code></p>
10+
11+
<pre>+-------------+---------+
12+
| Column Name | Type |
13+
+-------------+---------+
14+
| person_id | int |
15+
| person_name | varchar |
16+
| weight | int |
17+
| turn | int |
18+
+-------------+---------+
19+
person_id 是这个表的主键。
20+
该表展示了所有等待电梯的人的信息。
21+
表中 person_id 和 turn 列将包含从 1 到 n 的所有数字,其中 n 是表中的行数。
22+
</pre>
23+
24+
<p>&nbsp;</p>
25+
26+
<p>电梯最大载重量为 <strong>1000</strong>。</p>
27+
28+
<p>写一条 SQL 查询语句查找最后一个能进入电梯且不超过重量限制的 <code>person_name</code> 。题目确保队列中第一位的人可以进入电梯 。</p>
29+
30+
<p>查询结果如下所示 :</p>
31+
32+
<pre>Queue 表
33+
+-----------+-------------------+--------+------+
34+
| person_id | person_name | weight | turn |
35+
+-----------+-------------------+--------+------+
36+
| 5 | George Washington | 250 | 1 |
37+
| 3 | John Adams | 350 | 2 |
38+
| 6 | Thomas Jefferson | 400 | 3 |
39+
| 2 | Will Johnliams | 200 | 4 |
40+
| 4 | Thomas Jefferson | 175 | 5 |
41+
| 1 | James Elephant | 500 | 6 |
42+
+-----------+-------------------+--------+------+
43+
44+
Result 表
45+
+-------------------+
46+
| person_name |
47+
+-------------------+
48+
| Thomas Jefferson |
49+
+-------------------+
50+
51+
为了简化,Queue 表按 turn 列由小到大排序。
52+
上例中 George Washington(id 5), John Adams(id 3) 和 Thomas Jefferson(id 6) 将可以进入电梯,因为他们的体重和为 250 +たす 350 +たす 400 = 1000。
53+
Thomas Jefferson(id 6) 是最后一个体重合适并进入电梯的人。
54+
</pre>
55+
56+
57+
## 解法
58+
59+
<!-- 这里可写通用的实现逻辑 -->
60+
61+
<!-- tabs:start -->
62+
63+
### **SQL**
64+
65+
<!-- 这里可写当前语言的特殊实现逻辑 -->
66+
67+
```sql
68+
69+
```
70+
71+
<!-- tabs:end -->

‎solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [1204. Last Person to Fit in the Bus](https://leetcode.com/problems/last-person-to-fit-in-the-bus)
2+
3+
[中文文档](/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Bus/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Queue</code></p>
8+
9+
<pre>
10+
+-------------+---------+
11+
| Column Name | Type |
12+
+-------------+---------+
13+
| person_id | int |
14+
| person_name | varchar |
15+
| weight | int |
16+
| turn | int |
17+
+-------------+---------+
18+
person_id is the primary key column for this table.
19+
This table has the information about all people waiting for a bus.
20+
The person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.
21+
turn determines the order of which the people will board the bus, where turn=1 denotes the first person to board and turn=n denotes the last person to board.
22+
weight is the weight of the person in kilograms.
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
27+
<p>There is a queue of people waiting to board a bus. However, the bus has a weight limit of <strong>1000 kilograms</strong>, so there may be some people who cannot board.</p>
28+
29+
<p>Write an SQL query to find the <code>person_name</code> of the <strong>last person</strong> that can fit on the bus without exceeding the weight limit. The testcases are generated such that the first person does not exceed the weight limit.</p>
30+
31+
<p>The query result format is in the following example:</p>
32+
33+
<p>&nbsp;</p>
34+
35+
<pre>
36+
Queue table:
37+
+-----------+-------------+--------+------+
38+
| person_id | person_name | weight | turn |
39+
+-----------+-------------+--------+------+
40+
| 5 | Alice | 250 | 1 |
41+
| 4 | Bob | 175 | 5 |
42+
| 3 | Alex | 350 | 2 |
43+
| 6 | John Cena | 400 | 3 |
44+
| 1 | Winston | 500 | 6 |
45+
| 2 | Marie | 200 | 4 |
46+
+-----------+-------------+--------+------+
47+
48+
Result table
49+
+-------------+
50+
| person_name |
51+
+-------------+
52+
| John Cena |
53+
+-------------+
54+
55+
The table is ordered by the turn for simplicity.
56+
+------+----+-----------+--------+--------------+
57+
| Turn | ID | Name | Weight | Total Weight |
58+
+------+----+-----------+--------+--------------+
59+
| 1 | 5 | Alice | 250 | 250 |
60+
| 2 | 3 | Alex | 350 | 600 |
61+
| 3 | 6 | John Cena | 400 | 1000 | (last person to board)
62+
| 4 | 2 | Marie | 200 | 1200 | (cannot board)
63+
| 5 | 4 | Bob | 175 | ___ |
64+
| 6 | 1 | Winston | 500 | ___ |
65+
+------+----+-----------+--------+--------------+
66+
</pre>
67+
68+
## Solutions
69+
70+
<!-- tabs:start -->
71+
72+
### **SQL**
73+
74+
```sql
75+
76+
```
77+
78+
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /