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 80a8eaf

Browse files
author
Shuo
authored
Merge pull request #721 from openset/develop
Add: descriptions
2 parents 4fe70a9 + a72867f commit 80a8eaf

File tree

146 files changed

+5739
-22
lines changed

Some content is hidden

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

146 files changed

+5739
-22
lines changed

‎problems/active-businesses/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,46 @@
1111

1212
## [1126. Active Businesses (Medium)](https://leetcode.com/problems/active-businesses "")
1313

14+
<p>Table: <code>Events</code></p>
1415

16+
<pre>
17+
+---------------+---------+
18+
| Column Name | Type |
19+
+---------------+---------+
20+
| business_id | int |
21+
| event_type | varchar |
22+
| occurences | int |
23+
+---------------+---------+
24+
(business_id, event_type) is the primary key of this table.
25+
Each row in the table logs the info that an event of some type occured at some business for a number of times.</pre>
26+
27+
<p>&nbsp;</p>
28+
29+
<p>Write an SQL query to find all <em>active businesses</em>.</p>
30+
31+
<p>An active business is a business that has more than one event type&nbsp;with occurences greater than the average occurences of that event type&nbsp;among all businesses.</p>
32+
33+
<p>The query result format is in the following example:</p>
34+
35+
<pre>
36+
Events table:
37+
+-------------+------------+------------+
38+
| business_id | event_type | occurences |
39+
+-------------+------------+------------+
40+
| 1 | reviews | 7 |
41+
| 3 | reviews | 3 |
42+
| 1 | ads | 11 |
43+
| 2 | ads | 7 |
44+
| 3 | ads | 6 |
45+
| 1 | page views | 3 |
46+
| 2 | page views | 12 |
47+
+-------------+------------+------------+
48+
49+
Result table:
50+
+-------------+
51+
| business_id |
52+
+-------------+
53+
| 1 |
54+
+-------------+
55+
Average for &#39;reviews&#39;, &#39;ads&#39; and &#39;page views&#39; are (7+3)/2=5, (11+7+6)/3=8, (3+12)/2=7.5 respectively.
56+
Business with id 1 has 7 &#39;reviews&#39; events (more than 5) and 11 &#39;ads&#39; events (more than 8) so it is an active business.</pre>

‎problems/actors-and-directors-who-cooperated-at-least-three-times/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,44 @@
1111

1212
## [1050. Actors and Directors Who Cooperated At Least Three Times (Easy)](https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times "合作过至少三次的演员和导演")
1313

14+
<p>Table: <code>ActorDirector</code></p>
1415

16+
<pre>
17+
+-------------+---------+
18+
| Column Name | Type |
19+
+-------------+---------+
20+
| actor_id | int |
21+
| director_id | int |
22+
| timestamp | int |
23+
+-------------+---------+
24+
timestamp is the primary key column for this table.
25+
</pre>
26+
27+
<p>&nbsp;</p>
28+
29+
<p>Write a SQL query for a report that provides the pairs <code>(actor_id, director_id)</code> where the actor have cooperated with the director at least 3 times.</p>
30+
31+
<p><strong>Example:</strong></p>
32+
33+
<pre>
34+
ActorDirector table:
35+
+-------------+-------------+-------------+
36+
| actor_id | director_id | timestamp |
37+
+-------------+-------------+-------------+
38+
| 1 | 1 | 0 |
39+
| 1 | 1 | 1 |
40+
| 1 | 1 | 2 |
41+
| 1 | 2 | 3 |
42+
| 1 | 2 | 4 |
43+
| 2 | 1 | 5 |
44+
| 2 | 1 | 6 |
45+
+-------------+-------------+-------------+
46+
47+
Result table:
48+
+-------------+-------------+
49+
| actor_id | director_id |
50+
+-------------+-------------+
51+
| 1 | 1 |
52+
+-------------+-------------+
53+
The only pair is (1, 1) where they cooperated exactly 3 times.
54+
</pre>

‎problems/add-bold-tag-in-string/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@
1111

1212
## [616. Add Bold Tag in String (Medium)](https://leetcode.com/problems/add-bold-tag-in-string "给字符串添加加粗标签")
1313

14+
Given a string <b>s</b> and a list of strings <b>dict</b>, you need to add a closed pair of bold tag <code>&lt;b&gt;</code> and <code>&lt;/b&gt;</code> to wrap the substrings in s that exist in dict. If two such substrings overlap, you need to wrap them together by only one pair of closed bold tag. Also, if two substrings wrapped by bold tags are consecutive, you need to combine them.
1415

16+
<p><b>Example 1:</b><br />
17+
<pre>
18+
<b>Input:</b>
19+
s = "abcxyz123"
20+
dict = ["abc","123"]
21+
<b>Output:</b>
22+
"&lt;b&gt;abc&lt;/b&gt;xyz&lt;b&gt;123&lt;/b&gt;"
23+
</pre>
24+
</p>
25+
26+
<p><b>Example 2:</b><br />
27+
<pre>
28+
<b>Input:</b>
29+
s = "aaabbcc"
30+
dict = ["aaa","aab","bc"]
31+
<b>Output:</b>
32+
"&lt;b&gt;aaabbc&lt;/b&gt;c"
33+
</pre>
34+
</p>
35+
36+
<p><b>Note:</b><br>
37+
<ol>
38+
<li>The given dict won't contain duplicates, and its length won't exceed 100.</li>
39+
<li>All the strings in input have length in range [1, 1000]. </li>
40+
</ol>
41+
</p>
1542

1643
### Related Topics
1744
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]

‎problems/alien-dictionary/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,58 @@
1111

1212
## [269. Alien Dictionary (Hard)](https://leetcode.com/problems/alien-dictionary "火星词典")
1313

14+
<p>There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of <b>non-empty</b> words from the dictionary, where <b>words are sorted lexicographically by the rules of this new language</b>. Derive the order of letters in this language.</p>
1415

16+
<p><b>Example 1:</b></p>
17+
18+
<pre>
19+
<strong>Input:</strong>
20+
[
21+
&quot;wrt&quot;,
22+
&quot;wrf&quot;,
23+
&quot;er&quot;,
24+
&quot;ett&quot;,
25+
&quot;rftt&quot;
26+
]
27+
28+
<strong>Output: </strong><code>&quot;wertf&quot;</code>
29+
</pre>
30+
31+
<p><b>Example 2:</b></p>
32+
33+
<pre>
34+
<strong>Input:</strong>
35+
[
36+
&quot;z&quot;,
37+
&quot;x&quot;
38+
]
39+
40+
<strong>Output: </strong><code>&quot;zx&quot;</code>
41+
</pre>
42+
43+
<p><b>Example 3:</b></p>
44+
45+
<pre>
46+
<strong>Input:</strong>
47+
[
48+
&quot;z&quot;,
49+
&quot;x&quot;,
50+
&quot;z&quot;
51+
]
52+
53+
<strong>Output:</strong> <code>&quot;&quot;</code>&nbsp;
54+
55+
<strong>Explanation:</strong> The order is invalid, so return <code>&quot;&quot;</code>.
56+
</pre>
57+
58+
<p><b>Note:</b></p>
59+
60+
<ol>
61+
<li>You may assume all letters are in lowercase.</li>
62+
<li>You may assume that if a is a prefix of b, then a must appear before b in the given dictionary.</li>
63+
<li>If the order is invalid, return an empty string.</li>
64+
<li>There may be multiple valid order of letters, return any one of them is fine.</li>
65+
</ol>
1566

1667
### Related Topics
1768
[[Graph](https://github.com/openset/leetcode/tree/master/tag/graph/README.md)]

‎problems/analyze-user-website-visit-pattern/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,51 @@
1111

1212
## [1152. Analyze User Website Visit Pattern (Medium)](https://leetcode.com/problems/analyze-user-website-visit-pattern "用户网站访问行为分析")
1313

14+
<p>We are given some website visits: the user with name&nbsp;<code>username[i]</code> visited the website&nbsp;<code>website[i]</code> at time <code>timestamp[i]</code>.</p>
1415

16+
<p>A <em>3-sequence</em>&nbsp;is a list of&nbsp;websites of length 3 sorted in ascending order&nbsp;by the time of their visits.&nbsp; (The websites in a 3-sequence are not necessarily distinct.)</p>
17+
18+
<p>Find the 3-sequence visited&nbsp;by the largest number of users. If there is more than one solution, return the lexicographically smallest such 3-sequence.</p>
19+
20+
<p>&nbsp;</p>
21+
22+
<p><strong>Example 1:</strong></p>
23+
24+
<pre>
25+
<strong>Input: </strong>username = <span>[&quot;joe&quot;,&quot;joe&quot;,&quot;joe&quot;,&quot;james&quot;,&quot;james&quot;,&quot;james&quot;,&quot;james&quot;,&quot;mary&quot;,&quot;mary&quot;,&quot;mary&quot;]</span>, timestamp = <span id="example-input-1-2">[1,2,3,4,5,6,7,8,9,10]</span>, website = <span id="example-input-1-3">[&quot;home&quot;,&quot;about&quot;,&quot;career&quot;,&quot;home&quot;,&quot;cart&quot;,&quot;maps&quot;,&quot;home&quot;,&quot;home&quot;,&quot;about&quot;,&quot;career&quot;]</span>
26+
<strong>Output: </strong><span id="example-output-1">[&quot;home&quot;,&quot;about&quot;,&quot;career&quot;]</span>
27+
<strong>Explanation: </strong>
28+
The tuples in this example are:
29+
[&quot;joe&quot;, 1, &quot;home&quot;]
30+
[&quot;joe&quot;, 2, &quot;about&quot;]
31+
[&quot;joe&quot;, 3, &quot;career&quot;]
32+
[&quot;james&quot;, 4, &quot;home&quot;]
33+
[&quot;james&quot;, 5, &quot;cart&quot;]
34+
[&quot;james&quot;, 6, &quot;maps&quot;]
35+
[&quot;james&quot;, 7, &quot;home&quot;]
36+
[&quot;mary&quot;, 8, &quot;home&quot;]
37+
[&quot;mary&quot;, 9, &quot;about&quot;]
38+
[&quot;mary&quot;, 10, &quot;career&quot;]
39+
The 3-sequence (&quot;home&quot;, &quot;about&quot;, &quot;career&quot;) was visited at least once by <strong>2</strong> users.
40+
The 3-sequence (&quot;home&quot;, &quot;cart&quot;, &quot;maps&quot;) was visited at least once by 1 user.
41+
The 3-sequence (&quot;home&quot;, &quot;cart&quot;, &quot;home&quot;) was visited at least once by 1 user.
42+
The 3-sequence (&quot;home&quot;, &quot;maps&quot;, &quot;home&quot;) was visited at least once by 1 user.
43+
The 3-sequence (&quot;cart&quot;, &quot;maps&quot;, &quot;home&quot;) was visited at least once by 1 user.
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
48+
<p><strong>Note:</strong></p>
49+
50+
<ol>
51+
<li><code>3 &lt;= N = username.length = timestamp.length = website.length &lt;= 50</code></li>
52+
<li><code>1 &lt;= username[i].length &lt;= 10</code></li>
53+
<li><code>0 &lt;= timestamp[i] &lt;= 10^9</code></li>
54+
<li><code>1 &lt;= website[i].length &lt;= 10</code></li>
55+
<li>Both <code>username[i]</code> and <code>website[i]</code> contain only lowercase characters.</li>
56+
<li>It is guaranteed that there is at least one user who visited at least 3 websites.</li>
57+
<li>No user visits two websites at the same time.</li>
58+
</ol>
1559

1660
### Related Topics
1761
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]

‎problems/armstrong-number/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,37 @@
1111

1212
## [1134. Armstrong Number (Easy)](https://leetcode.com/problems/armstrong-number "阿姆斯特朗数")
1313

14+
<p>The k-digit number <code>N</code> is an Armstrong number if and only if the k-th power of each digit sums to N.</p>
1415

16+
<p>Given a positive integer <code>N</code>, return true if and only if it is an Armstrong number.</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong>Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input: </strong><span id="example-input-1-1">153</span>
24+
<strong>Output: </strong><span id="example-output-1">true</span>
25+
<strong>Explanation: </strong>
26+
153 is a 3-digit number, and 153 = 1^3 + 5^3 + 3^3.
27+
</pre>
28+
29+
<p><strong>Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input: </strong><span id="example-input-2-1">123</span>
33+
<strong>Output: </strong><span id="example-output-2">false</span>
34+
<strong>Explanation: </strong>
35+
123 is a 3-digit number, and 123 != 1^3 + 2^3 + 3^3 = 36.
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
40+
<p><strong>Note:</strong></p>
41+
42+
<ol>
43+
<li><code>1 &lt;= N &lt;= 10^8</code></li>
44+
</ol>
1545

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

‎problems/array-transformation/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,47 @@
1111

1212
## [1243. Array Transformation (Easy)](https://leetcode.com/problems/array-transformation "数组变换")
1313

14+
<p>Given an initial array <code>arr</code>, every day you produce a new array using the array of the previous day.</p>
1415

16+
<p>On the <code>i</code>-th day, you do the following operations on the array of day&nbsp;<code>i-1</code>&nbsp;to produce the array of day <code>i</code>:</p>
17+
18+
<ol>
19+
<li>If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented.</li>
20+
<li>If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented.</li>
21+
<li>The first&nbsp;and last elements never change.</li>
22+
</ol>
23+
24+
<p>After some days, the array does not change. Return that final array.</p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> arr = [6,2,3,4]
31+
<strong>Output:</strong> [6,3,3,4]
32+
<strong>Explanation: </strong>
33+
On the first day, the array is changed from [6,2,3,4] to [6,3,3,4].
34+
No more operations can be done to this array.
35+
</pre>
36+
37+
<p><strong>Example 2:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> arr = [1,6,3,4,3,5]
41+
<strong>Output:</strong> [1,4,4,4,4,5]
42+
<strong>Explanation: </strong>
43+
On the first day, the array is changed from [1,6,3,4,3,5] to [1,5,4,3,4,5].
44+
On the second day, the array is changed from [1,5,4,3,4,5] to [1,4,4,4,4,5].
45+
No more operations can be done to this array.
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= arr.length &lt;= 100</code></li>
53+
<li><code>1 &lt;= arr[i] &lt;= 100</code></li>
54+
</ul>
1555

1656
### Related Topics
1757
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

‎problems/article-views-i/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,46 @@
1111

1212
## [1148. Article Views I (Easy)](https://leetcode.com/problems/article-views-i "文章浏览 I")
1313

14+
<p>Table: <code>Views</code></p>
1415

16+
<pre>
17+
+---------------+---------+
18+
| Column Name | Type |
19+
+---------------+---------+
20+
| article_id | int |
21+
| author_id | int |
22+
| viewer_id | int |
23+
| view_date | date |
24+
+---------------+---------+
25+
There is no primary key for this table, it may have duplicate rows.
26+
Each row of this table indicates that some viewer viewed an article (written by some author) on some date.
27+
Note that equal author_id and viewer_id indicate the same person.</pre>
28+
29+
<p>&nbsp;</p>
30+
31+
<p>Write an SQL query to find all the authors that viewed at least one of their own articles, sorted in ascending order by their id.</p>
32+
33+
<p>The query result format is in the following example:</p>
34+
35+
<pre>
36+
Views table:
37+
+------------+-----------+-----------+------------+
38+
| article_id | author_id | viewer_id | view_date |
39+
+------------+-----------+-----------+------------+
40+
| 1 | 3 | 5 | 2019年08月01日 |
41+
| 1 | 3 | 6 | 2019年08月02日 |
42+
| 2 | 7 | 7 | 2019年08月01日 |
43+
| 2 | 7 | 6 | 2019年08月02日 |
44+
| 4 | 7 | 1 | 2019年07月22日 |
45+
| 3 | 4 | 4 | 2019年07月21日 |
46+
| 3 | 4 | 4 | 2019年07月21日 |
47+
+------------+-----------+-----------+------------+
48+
49+
Result table:
50+
+------+
51+
| id |
52+
+------+
53+
| 4 |
54+
| 7 |
55+
+------+
56+
</pre>

0 commit comments

Comments
(0)

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