You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: problems/2-keys-keyboard/README.md
+18-16Lines changed: 18 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,36 +11,38 @@
11
11
12
12
## 650. 2 Keys Keyboard (Medium)
13
13
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 'A' is present. You can perform two operations on this notepad for each step:</p>
15
+
16
16
<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>
19
19
</ol>
20
-
</p>
21
20
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> </p>
22
+
23
+
<p>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'.</p>
24
+
25
+
<p><b>Example 1:</b></p>
25
26
26
-
<p><b>Example 1:</b><br />
27
27
<pre>
28
28
<b>Input:</b> 3
29
29
<b>Output:</b> 3
30
30
<b>Explanation:</b>
31
-
Intitally, we have one character 'A'.
31
+
Intitally, we have one character 'A'.
32
32
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 'AA'.
34
+
In step 3, we use <b>Paste</b> operation to get 'AAA'.
35
35
</pre>
36
-
</p>
37
36
37
+
<p> </p>
38
+
39
+
<p><b>Note:</b></p>
38
40
39
-
<p><b>Note:</b><br>
40
41
<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>
Copy file name to clipboardExpand all lines: problems/average-salary-departments-vs-company/README.md
+32-12Lines changed: 32 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,10 @@
11
11
12
12
## 615. Average Salary: Departments VS Company (Hard)
13
13
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's average salary.
15
+
<p> </p>
16
16
Table: <code>salary</code>
17
+
17
18
<pre>
18
19
| id | employee_id | amount | pay_date |
19
20
|----|-------------|--------|------------|
@@ -23,29 +24,48 @@ Table: <code>salary</code>
23
24
| 4 | 1 | 7000 | 2017年02月28日 |
24
25
| 5 | 2 | 6000 | 2017年02月28日 |
25
26
| 6 | 3 | 8000 | 2017年02月28日 |
26
-
</pre></p>
27
+
</pre>
28
+
29
+
<p> </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> </p>
27
33
28
-
The <b>employee_id</b> column refers to the <b>employee_id</b> in the following table <code>employee</code>.</p>
29
34
<pre>
30
35
| employee_id | department_id |
31
36
|-------------|---------------|
32
37
| 1 | 1 |
33
38
| 2 | 2 |
34
39
| 3 | 2 |
35
-
</pre></p>
40
+
</pre>
41
+
42
+
<p> </p>
43
+
So for the sample data above, the result is:
44
+
45
+
<p> </p>
36
46
37
-
So for the sample data above, the result is:</p>
38
47
<pre>
39
48
| pay_month | department_id | comparison |
40
49
|-----------|---------------|-------------|
41
50
| 2017-03 | 1 | higher |
42
51
| 2017-03 | 2 | lower |
43
52
| 2017-02 | 1 | same |
44
53
| 2017-02 | 2 | same |
45
-
</pre></p>
54
+
</pre>
55
+
56
+
<p> </p>
57
+
<b>Explanation</b>
58
+
59
+
<p> </p>
60
+
In March, the company's average salary is (9000+6000+10000)/3 = 8333.33...
61
+
62
+
<p> </p>
63
+
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.
64
+
65
+
<p> </p>
66
+
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.
67
+
68
+
<p> </p>
69
+
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.
46
70
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>
Copy file name to clipboardExpand all lines: problems/beautiful-arrangement/README.md
+28-19Lines changed: 28 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,37 +11,46 @@
11
11
12
12
## 526. Beautiful Arrangement (Medium)
13
13
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 <= i <= N) in this array:</p>
15
+
16
16
<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>
19
19
</ol>
20
-
</p>
21
20
22
-
<p>
23
-
Now given N, how many beautiful arrangements can you construct?
24
-
</p>
21
+
<p> </p>
22
+
23
+
<p>Now given N, how many beautiful arrangements can you construct?</p>
24
+
25
+
<p><b>Example 1:</b></p>
25
26
26
-
<p><b>Example 1:</b><br />
27
27
<pre>
28
28
<b>Input:</b> 2
29
29
<b>Output:</b> 2
30
30
<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.
37
43
</pre>
38
-
</p>
39
44
40
-
<p><b>Note:</b><br>
45
+
<p> </p>
46
+
47
+
<p><b>Note:</b></p>
48
+
41
49
<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>
Copy file name to clipboardExpand all lines: problems/bulb-switcher-ii/README.md
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,51 +11,50 @@
11
11
12
12
## 672. Bulb Switcher II (Medium)
13
13
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>
17
15
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>
20
17
21
18
<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>
26
23
</ol>
27
-
</p>
28
24
25
+
<p> </p>
26
+
27
+
<p><b>Example 1:</b></p>
29
28
30
-
<p><b>Example 1:</b><br />
31
29
<pre>
32
30
<b>Input:</b> n = 1, m = 1.
33
31
<b>Output:</b> 2
34
32
<b>Explanation:</b> Status can be: [on], [off]
35
33
</pre>
36
-
</p>
37
34
35
+
<p> </p>
36
+
37
+
<p><b>Example 2:</b></p>
38
38
39
-
<p><b>Example 2:</b><br />
40
39
<pre>
41
40
<b>Input:</b> n = 2, m = 1.
42
41
<b>Output:</b> 3
43
42
<b>Explanation:</b> Status can be: [on, off], [off, on], [off, off]
44
43
</pre>
45
-
</p>
46
44
45
+
<p> </p>
46
+
47
+
<p><b>Example 3:</b></p>
47
48
48
-
<p><b>Example 3:</b><br />
49
49
<pre>
50
50
<b>Input:</b> n = 3, m = 1.
51
51
<b>Output:</b> 4
52
52
<b>Explanation:</b> Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
53
53
</pre>
54
-
</p>
55
54
56
-
<p><b>Note:</b>
57
-
<code>n</code> and <code>m</code> both fit in range [0, 1000].
58
-
</p>
55
+
<p> </p>
56
+
57
+
<p><b>Note:</b> <code>n</code> and <code>m</code> both fit in range [0, 1000].</p>
0 commit comments