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 76a24bf

Browse files
author
Shuo
authored
Merge pull request #405 from openset/develop
Update: description
2 parents a3e4d83 + 9544656 commit 76a24bf

File tree

10 files changed

+208
-132
lines changed

10 files changed

+208
-132
lines changed

‎problems/2-keys-keyboard/README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,38 @@
1111

1212
## 650. 2 Keys Keyboard (Medium)
1313

14-
<p>
15-
Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:
14+
<p>Initially on a notepad only one character &#39;A&#39; is present. You can perform two operations on this notepad for each step:</p>
15+
1616
<ol>
17-
<li><code>Copy All</code>: You can copy all the characters present on the notepad (partial copy is not allowed).</li>
18-
<li><code>Paste</code>: You can paste the characters which are copied <b>last time</b>.</li>
17+
<li><code>Copy All</code>: You can copy all the characters present on the notepad (partial copy is not allowed).</li>
18+
<li><code>Paste</code>: You can paste the characters which are copied <b>last time</b>.</li>
1919
</ol>
20-
</p>
2120

22-
<p>
23-
Given a number <code>n</code>. You have to get <b>exactly</b> <code>n</code> 'A' on the notepad by performing the minimum number of steps permitted. Output the minimum number of steps to get <code>n</code> 'A'.
24-
</p>
21+
<p>&nbsp;</p>
22+
23+
<p>Given a number <code>n</code>. You have to get <b>exactly</b> <code>n</code> &#39;A&#39; on the notepad by performing the minimum number of steps permitted. Output the minimum number of steps to get <code>n</code> &#39;A&#39;.</p>
24+
25+
<p><b>Example 1:</b></p>
2526

26-
<p><b>Example 1:</b><br />
2727
<pre>
2828
<b>Input:</b> 3
2929
<b>Output:</b> 3
3030
<b>Explanation:</b>
31-
Intitally, we have one character 'A'.
31+
Intitally, we have one character &#39;A&#39;.
3232
In step 1, we use <b>Copy All</b> operation.
33-
In step 2, we use <b>Paste</b> operation to get 'AA'.
34-
In step 3, we use <b>Paste</b> operation to get 'AAA'.
33+
In step 2, we use <b>Paste</b> operation to get &#39;AA&#39;.
34+
In step 3, we use <b>Paste</b> operation to get &#39;AAA&#39;.
3535
</pre>
36-
</p>
3736

37+
<p>&nbsp;</p>
38+
39+
<p><b>Note:</b></p>
3840

39-
<p><b>Note:</b><br>
4041
<ol>
41-
<li>The <code>n</code> will be in the range [1, 1000].</li>
42+
<li>The <code>n</code> will be in the range [1, 1000].</li>
4243
</ol>
43-
</p>
44+
45+
<p>&nbsp;</p>
4446

4547
### Related Topics
4648
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]

‎problems/average-salary-departments-vs-company/README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
## 615. Average Salary: Departments VS Company (Hard)
1313

14-
Given two tables as below, write a query to display the comparison result (higher/lower/same) of the average salary of employees in a department to the company's average salary.</p>
15-
14+
Given two tables as below, write a query to display the comparison result (higher/lower/same) of the average salary of employees in a department to the company&#39;s average salary.
15+
<p>&nbsp;</p>
1616
Table: <code>salary</code>
17+
1718
<pre>
1819
| id | employee_id | amount | pay_date |
1920
|----|-------------|--------|------------|
@@ -23,29 +24,48 @@ Table: <code>salary</code>
2324
| 4 | 1 | 7000 | 2017年02月28日 |
2425
| 5 | 2 | 6000 | 2017年02月28日 |
2526
| 6 | 3 | 8000 | 2017年02月28日 |
26-
</pre></p>
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
The <b>employee_id</b> column refers to the <b>employee_id</b> in the following table <code>employee</code>.
31+
32+
<p>&nbsp;</p>
2733

28-
The <b>employee_id</b> column refers to the <b>employee_id</b> in the following table <code>employee</code>.</p>
2934
<pre>
3035
| employee_id | department_id |
3136
|-------------|---------------|
3237
| 1 | 1 |
3338
| 2 | 2 |
3439
| 3 | 2 |
35-
</pre></p>
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
So for the sample data above, the result is:
44+
45+
<p>&nbsp;</p>
3646

37-
So for the sample data above, the result is:</p>
3847
<pre>
3948
| pay_month | department_id | comparison |
4049
|-----------|---------------|-------------|
4150
| 2017-03 | 1 | higher |
4251
| 2017-03 | 2 | lower |
4352
| 2017-02 | 1 | same |
4453
| 2017-02 | 2 | same |
45-
</pre></p>
54+
</pre>
55+
56+
<p>&nbsp;</p>
57+
<b>Explanation</b>
58+
59+
<p>&nbsp;</p>
60+
In March, the company&#39;s average salary is (9000+6000+10000)/3 = 8333.33...
61+
62+
<p>&nbsp;</p>
63+
The average salary for department &#39;1&#39; is 9000, which is the salary of <b>employee_id</b> &#39;1&#39; since there is only one employee in this department. So the comparison result is &#39;higher&#39; since 9000 &gt; 8333.33 obviously.
64+
65+
<p>&nbsp;</p>
66+
The average salary of department &#39;2&#39; is (6000 + 10000)/2 = 8000, which is the average of <b>employee_id</b> &#39;2&#39; and &#39;3&#39;. So the comparison result is &#39;lower&#39; since 8000 &lt; 8333.33.
67+
68+
<p>&nbsp;</p>
69+
With he same formula for the average salary comparison in February, the result is &#39;same&#39; since both the department &#39;1&#39; and &#39;2&#39; have the same average salary with the company, which is 7000.
4670

47-
<b>Explanation</b></p>
48-
In March, the company's average salary is (9000+6000+10000)/3 = 8333.33...</p>
49-
The average salary for department '1' is 9000, which is the salary of <b>employee_id</b> '1' since there is only one employee in this department. So the comparison result is 'higher' since 9000 > 8333.33 obviously.</p>
50-
The average salary of department '2' is (6000 + 10000)/2 = 8000, which is the average of <b>employee_id</b> '2' and '3'. So the comparison result is 'lower' since 8000 < 8333.33.</p>
51-
With he same formula for the average salary comparison in February, the result is 'same' since both the department '1' and '2' have the same average salary with the company, which is 7000.</p>
71+
<p>&nbsp;</p>

‎problems/beautiful-arrangement/README.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,46 @@
1111

1212
## 526. Beautiful Arrangement (Medium)
1313

14-
<p>
15-
Suppose you have <b>N</b> integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these <b>N</b> numbers successfully if one of the following is true for the i<sub>th</sub> position (1 <= i <= N) in this array:
14+
<p>Suppose you have <b>N</b> integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these <b>N</b> numbers successfully if one of the following is true for the i<sub>th</sub> position (1 &lt;= i &lt;= N) in this array:</p>
15+
1616
<ol>
17-
<li>The number at the i<sub>th</sub> position is divisible by <b>i</b>.</li>
18-
<li><b>i</b> is divisible by the number at the i<sub>th</sub> position.</li>
17+
<li>The number at the i<sub>th</sub> position is divisible by <b>i</b>.</li>
18+
<li><b>i</b> is divisible by the number at the i<sub>th</sub> position.</li>
1919
</ol>
20-
</p>
2120

22-
<p>
23-
Now given N, how many beautiful arrangements can you construct?
24-
</p>
21+
<p>&nbsp;</p>
22+
23+
<p>Now given N, how many beautiful arrangements can you construct?</p>
24+
25+
<p><b>Example 1:</b></p>
2526

26-
<p><b>Example 1:</b><br />
2727
<pre>
2828
<b>Input:</b> 2
2929
<b>Output:</b> 2
3030
<b>Explanation:</b>
31-
<br/>The first beautiful arrangement is [1, 2]:
32-
<br/>Number at the 1st position (i=1) is 1, and 1 is divisible by i (i=1).
33-
<br/>Number at the 2nd position (i=2) is 2, and 2 is divisible by i (i=2).
34-
<br/>The second beautiful arrangement is [2, 1]:
35-
<br/>Number at the 1st position (i=1) is 2, and 2 is divisible by i (i=1).
36-
<br/>Number at the 2nd position (i=2) is 1, and i (i=2) is divisible by 1.
31+
32+
The first beautiful arrangement is [1, 2]:
33+
34+
Number at the 1st position (i=1) is 1, and 1 is divisible by i (i=1).
35+
36+
Number at the 2nd position (i=2) is 2, and 2 is divisible by i (i=2).
37+
38+
The second beautiful arrangement is [2, 1]:
39+
40+
Number at the 1st position (i=1) is 2, and 2 is divisible by i (i=1).
41+
42+
Number at the 2nd position (i=2) is 1, and i (i=2) is divisible by 1.
3743
</pre>
38-
</p>
3944

40-
<p><b>Note:</b><br>
45+
<p>&nbsp;</p>
46+
47+
<p><b>Note:</b></p>
48+
4149
<ol>
42-
<li><b>N</b> is a positive integer and will not exceed 15.</li>
50+
<li><b>N</b> is a positive integer and will not exceed 15.</li>
4351
</ol>
44-
</p>
52+
53+
<p>&nbsp;</p>
4554

4655
### Related Topics
4756
[[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)]

‎problems/big-countries/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
## 595. Big Countries (Easy)
1313

14-
<p>There is a table <code>World</code> </p>
14+
<p>There is a table <code>World</code></p>
15+
1516
<pre>
1617
+-----------------+------------+------------+--------------+---------------+
1718
| name | continent | area | population | gdp |
@@ -23,13 +24,13 @@
2324
| Angola | Africa | 1246700 | 20609294 | 100990000 |
2425
+-----------------+------------+------------+--------------+---------------+
2526
</pre>
26-
<p>
27-
A country is big if it has an area of bigger than 3 million square km or a population of more than 25 million.
28-
</p><p>
29-
Write a SQL solution to output big countries' name, population and area.
30-
</p>
31-
<p>
32-
For example, according to the above table, we should output:
27+
28+
<p>A country is big if it has an area of bigger than 3 million square km or a population of more than 25 million.</p>
29+
30+
<p>Write a SQL solution to output big countries&#39; name, population and area.</p>
31+
32+
<p>For example, according to the above table, we should output:</p>
33+
3334
<pre>
3435
+--------------+-------------+--------------+
3536
| name | population | area |
@@ -38,4 +39,5 @@ For example, according to the above table, we should output:
3839
| Algeria | 37100000 | 2381741 |
3940
+--------------+-------------+--------------+
4041
</pre>
41-
</p>
42+
43+
<p>&nbsp;</p>

‎problems/bulb-switcher-ii/README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,50 @@
1111

1212
## 672. Bulb Switcher II (Medium)
1313

14-
<p>
15-
There is a room with <code>n</code> lights which are turned on initially and 4 buttons on the wall. After performing exactly <code>m</code> unknown operations towards buttons, you need to return how many different kinds of status of the <code>n</code> lights could be.
16-
</p>
14+
<p>There is a room with <code>n</code> lights which are turned on initially and 4 buttons on the wall. After performing exactly <code>m</code> unknown operations towards buttons, you need to return how many different kinds of status of the <code>n</code> lights could be.</p>
1715

18-
<p>
19-
Suppose <code>n</code> lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:
16+
<p>Suppose <code>n</code> lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:</p>
2017

2118
<ol>
22-
<li>Flip all the lights.</li>
23-
<li>Flip lights with even numbers.</li>
24-
<li>Flip lights with odd numbers.</li>
25-
<li>Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...</li>
19+
<li>Flip all the lights.</li>
20+
<li>Flip lights with even numbers.</li>
21+
<li>Flip lights with odd numbers.</li>
22+
<li>Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...</li>
2623
</ol>
27-
</p>
2824

25+
<p>&nbsp;</p>
26+
27+
<p><b>Example 1:</b></p>
2928

30-
<p><b>Example 1:</b><br />
3129
<pre>
3230
<b>Input:</b> n = 1, m = 1.
3331
<b>Output:</b> 2
3432
<b>Explanation:</b> Status can be: [on], [off]
3533
</pre>
36-
</p>
3734

35+
<p>&nbsp;</p>
36+
37+
<p><b>Example 2:</b></p>
3838

39-
<p><b>Example 2:</b><br />
4039
<pre>
4140
<b>Input:</b> n = 2, m = 1.
4241
<b>Output:</b> 3
4342
<b>Explanation:</b> Status can be: [on, off], [off, on], [off, off]
4443
</pre>
45-
</p>
4644

45+
<p>&nbsp;</p>
46+
47+
<p><b>Example 3:</b></p>
4748

48-
<p><b>Example 3:</b><br />
4949
<pre>
5050
<b>Input:</b> n = 3, m = 1.
5151
<b>Output:</b> 4
5252
<b>Explanation:</b> Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
5353
</pre>
54-
</p>
5554

56-
<p><b>Note:</b>
57-
<code>n</code> and <code>m</code> both fit in range [0, 1000].
58-
</p>
55+
<p>&nbsp;</p>
56+
57+
<p><b>Note:</b> <code>n</code> and <code>m</code> both fit in range [0, 1000].</p>
5958

6059
### Related Topics
6160
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]

‎problems/cherry-pickup/README.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,35 @@
1111

1212
## 741. Cherry Pickup (Hard)
1313

14-
<p>
15-
In a N x N <code>grid</code> representing a field of cherries, each cell is one of three possible integers.
16-
</p><p>
17-
<li>0 means the cell is empty, so you can pass through;</li>
18-
<li>1 means the cell contains a cherry, that you can pick up and pass through;</li>
19-
<li>-1 means the cell contains a thorn that blocks your way.</li>
20-
</p><p>
21-
Your task is to collect maximum number of cherries possible by following the rules below:
22-
</p><p>
23-
<li>Starting at the position (0, 0) and reaching (N-1, N-1) by moving right or down through valid path cells (cells with value 0 or 1);</li>
24-
<li>After reaching (N-1, N-1), returning to (0, 0) by moving left or up through valid path cells;</li>
25-
<li>When passing through a path cell containing a cherry, you pick it up and the cell becomes an empty cell (0);</li>
26-
<li>If there is no valid path between (0, 0) and (N-1, N-1), then no cherries can be collected.</li>
27-
</p><p>
28-
29-
<p><b>Example 1:</b><br />
14+
<p>In a N x N <code>grid</code> representing a field of cherries, each cell is one of three possible integers.</p>
15+
16+
<p>&nbsp;</p>
17+
18+
<ul>
19+
<li>0 means the cell is empty, so you can pass through;</li>
20+
<li>1 means the cell contains a cherry, that you can pick up and pass through;</li>
21+
<li>-1 means the cell contains a thorn that blocks your way.</li>
22+
</ul>
23+
24+
<p>&nbsp;</p>
25+
26+
<p>Your task is to collect maximum number of cherries possible by following the rules below:</p>
27+
28+
<p>&nbsp;</p>
29+
30+
<ul>
31+
<li>Starting at the position (0, 0) and reaching (N-1, N-1) by moving right or down through valid path cells (cells with value 0 or 1);</li>
32+
<li>After reaching (N-1, N-1), returning to (0, 0) by moving left or up through valid path cells;</li>
33+
<li>When passing through a path cell containing a cherry, you pick it up and the cell becomes an empty cell (0);</li>
34+
<li>If there is no valid path between (0, 0) and (N-1, N-1), then no cherries can be collected.</li>
35+
</ul>
36+
37+
<p>&nbsp;</p>
38+
39+
<p>&nbsp;</p>
40+
41+
<p><b>Example 1:</b></p>
42+
3043
<pre>
3144
<b>Input:</b> grid =
3245
[[0, 1, -1],
@@ -39,13 +52,19 @@ The player started at (0, 0) and went down, down, right right to reach (2, 2).
3952
Then, the player went left, up, up, left to return home, picking up one more cherry.
4053
The total number of cherries picked up is 5, and this is the maximum possible.
4154
</pre>
42-
</p>
4355

44-
<p><b>Note:</b>
45-
<li><code>grid</code> is an <code>N</code> by <code>N</code> 2D array, with <code>1 <= N <= 50</code>.</li>
46-
<li>Each <code>grid[i][j]</code> is an integer in the set <code>{-1, 0, 1}</code>.</li>
47-
<li>It is guaranteed that grid[0][0] and grid[N-1][N-1] are not -1.<li>
48-
</p>
56+
<p>&nbsp;</p>
57+
58+
<p><b>Note:</b></p>
59+
60+
<ul>
61+
<li><code>grid</code> is an <code>N</code> by <code>N</code> 2D array, with <code>1 &lt;= N &lt;= 50</code>.</li>
62+
<li>Each <code>grid[i][j]</code> is an integer in the set <code>{-1, 0, 1}</code>.</li>
63+
<li>It is guaranteed that grid[0][0] and grid[N-1][N-1] are not -1.</li>
64+
<li>
65+
<p>&nbsp;</p>
66+
</li>
67+
</ul>
4968

5069
### Related Topics
5170
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]

0 commit comments

Comments
(0)

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