Skip to content

Commit f92dd99

Browse files
author
Shuo
authored
Merge pull request #625 from openset/develop
Add: new
2 parents 40d392d + bc3ee1b commit f92dd99

File tree

33 files changed

+518
-20
lines changed

33 files changed

+518
-20
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ LeetCode Problems' Solutions
5454

5555
| # | Title | Solution | Difficulty |
5656
| :-: | - | - | :-: |
57+
| <span id="1157">1157</span> | [Online Majority Element In Subarray](https://leetcode.com/problems/online-majority-element-in-subarray "子数组中占绝大多数的元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/online-majority-element-in-subarray) | Hard |
58+
| <span id="1156">1156</span> | [Swap For Longest Repeated Character Substring](https://leetcode.com/problems/swap-for-longest-repeated-character-substring "单字符重复子串的最大长度") | [Go](https://github.com/openset/leetcode/tree/master/problems/swap-for-longest-repeated-character-substring) | Medium |
59+
| <span id="1155">1155</span> | [Number of Dice Rolls With Target Sum](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum "掷骰子的N种方法") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-dice-rolls-with-target-sum) | Medium |
60+
| <span id="1154">1154</span> | [Day of the Year](https://leetcode.com/problems/day-of-the-year "一年中的第几天") | [Go](https://github.com/openset/leetcode/tree/master/problems/day-of-the-year) | Easy |
61+
| <span id="1153">1153</span> | [String Transforms Into Another String](https://leetcode.com/problems/string-transforms-into-another-string "字符串转化") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/string-transforms-into-another-string) | Hard |
62+
| <span id="1152">1152</span> | [Analyze User Website Visit Pattern](https://leetcode.com/problems/analyze-user-website-visit-pattern "用户网站访问行为分析") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/analyze-user-website-visit-pattern) | Medium |
63+
| <span id="1151">1151</span> | [Minimum Swaps to Group All 1's Together](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together "最少交换次数来组合所有的 1") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-group-all-1s-together) | Medium |
64+
| <span id="1150">1150</span> | [Check If a Number Is Majority Element in a Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array "检查一个数是否在数组中占绝大多数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | Easy |
65+
| <span id="1149">1149</span> | [Article Views II](https://leetcode.com/problems/article-views-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/article-views-ii) | Medium |
66+
| <span id="1148">1148</span> | [Article Views I](https://leetcode.com/problems/article-views-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/article-views-i) | Easy |
5767
| <span id="1147">1147</span> | [Longest Chunked Palindrome Decomposition](https://leetcode.com/problems/longest-chunked-palindrome-decomposition "段式回文") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-chunked-palindrome-decomposition) | Hard |
5868
| <span id="1146">1146</span> | [Snapshot Array](https://leetcode.com/problems/snapshot-array "快照数组") | [Go](https://github.com/openset/leetcode/tree/master/problems/snapshot-array) | Medium |
5969
| <span id="1145">1145</span> | [Binary Tree Coloring Game](https://leetcode.com/problems/binary-tree-coloring-game "二叉树着色游戏") | [Go](https://github.com/openset/leetcode/tree/master/problems/binary-tree-coloring-game) | Medium |
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-group-all-1s-together "Minimum Swaps to Group All 1's Together")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/string-transforms-into-another-string "String Transforms Into Another String")
11+
12+
## 1152. Analyze User Website Visit Pattern (Medium)
13+
14+
15+
16+
### Related Topics
17+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
18+
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
19+
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
20+
21+
### Hints
22+
<details>
23+
<summary>Hint 1</summary>
24+
Let's find for every user separately the websites he visited.
25+
</details>
26+
27+
<details>
28+
<summary>Hint 2</summary>
29+
Consider all possible 3-sequences, find the number of distinct users who visited each of them.
30+
</details>
31+
32+
<details>
33+
<summary>Hint 3</summary>
34+
How to check if some user visited some 3-sequence ?
35+
</details>
36+
37+
<details>
38+
<summary>Hint 4</summary>
39+
Store for every user all the 3-sequence he visited.
40+
</details>

problems/article-views-i/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/longest-chunked-palindrome-decomposition "Longest Chunked Palindrome Decomposition")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/article-views-ii "Article Views II")
11+
12+
## 1148. Article Views I (Easy)
13+
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Create table If Not Exists Views (article_id int, author_id int, viewer_id int, view_date date);
2+
Truncate table Views;
3+
insert into Views (article_id, author_id, viewer_id, view_date) values ('1', '3', '5', '2019-08-01');
4+
insert into Views (article_id, author_id, viewer_id, view_date) values ('1', '3', '6', '2019-08-02');
5+
insert into Views (article_id, author_id, viewer_id, view_date) values ('2', '7', '7', '2019-08-01');
6+
insert into Views (article_id, author_id, viewer_id, view_date) values ('2', '7', '6', '2019-08-02');
7+
insert into Views (article_id, author_id, viewer_id, view_date) values ('4', '7', '1', '2019-07-22');
8+
insert into Views (article_id, author_id, viewer_id, view_date) values ('3', '4', '4', '2019-07-21');
9+
insert into Views (article_id, author_id, viewer_id, view_date) values ('3', '4', '4', '2019-07-21');

problems/article-views-ii/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/article-views-i "Article Views I")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/check-if-a-number-is-majority-element-in-a-sorted-array "Check If a Number Is Majority Element in a Sorted Array")
11+
12+
## 1149. Article Views II (Medium)
13+
14+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Create table If Not Exists Views (article_id int, author_id int, viewer_id int, view_date date);
2+
Truncate table Views;
3+
insert into Views (article_id, author_id, viewer_id, view_date) values ('1', '3', '5', '2019-08-01');
4+
insert into Views (article_id, author_id, viewer_id, view_date) values ('3', '4', '5', '2019-08-01');
5+
insert into Views (article_id, author_id, viewer_id, view_date) values ('1', '3', '6', '2019-08-02');
6+
insert into Views (article_id, author_id, viewer_id, view_date) values ('2', '7', '7', '2019-08-01');
7+
insert into Views (article_id, author_id, viewer_id, view_date) values ('2', '7', '6', '2019-08-02');
8+
insert into Views (article_id, author_id, viewer_id, view_date) values ('4', '7', '1', '2019-07-22');
9+
insert into Views (article_id, author_id, viewer_id, view_date) values ('3', '4', '4', '2019-07-21');
10+
insert into Views (article_id, author_id, viewer_id, view_date) values ('3', '4', '4', '2019-07-21');

problems/best-time-to-buy-and-sell-stock-ii/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre>
4545

4646
### Related Topics
47-
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
4847
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
48+
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
4949

5050
### Similar Questions
5151
1. [Best Time to Buy and Sell Stock](https://github.com/openset/leetcode/tree/master/problems/best-time-to-buy-and-sell-stock) (Easy)

problems/car-pooling/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
### Related Topics
7676
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
7777

78+
### Similar Questions
79+
1. [Meeting Rooms II](https://github.com/openset/leetcode/tree/master/problems/meeting-rooms-ii) (Medium)
80+
7881
### Hints
7982
<details>
8083
<summary>Hint 1</summary>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/article-views-ii "Article Views II")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-group-all-1s-together "Minimum Swaps to Group All 1's Together")
11+
12+
## 1150. Check If a Number Is Majority Element in a Sorted Array (Easy)
13+
14+
15+
16+
### Related Topics
17+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
18+
[[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)]
19+
20+
### Similar Questions
21+
1. [Majority Element](https://github.com/openset/leetcode/tree/master/problems/majority-element) (Easy)
22+
1. [Majority Element II](https://github.com/openset/leetcode/tree/master/problems/majority-element-ii) (Medium)
23+
24+
### Hints
25+
<details>
26+
<summary>Hint 1</summary>
27+
How to check if a given number target is a majority element?.
28+
</details>
29+
30+
<details>
31+
<summary>Hint 2</summary>
32+
Find the frequency of target and compare it to the length of the array.
33+
</details>
34+
35+
<details>
36+
<summary>Hint 3</summary>
37+
You can find the frequency of an element using Binary Search since the array is sorted.
38+
</details>
39+
40+
<details>
41+
<summary>Hint 4</summary>
42+
Using Binary Search, find the first and last occurrences of A. Then just calculate the difference between the indexes of these occurrences.
43+
</details>

problems/climbing-stairs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
### Similar Questions
4545
1. [Min Cost Climbing Stairs](https://github.com/openset/leetcode/tree/master/problems/min-cost-climbing-stairs) (Easy)
4646
1. [Fibonacci Number](https://github.com/openset/leetcode/tree/master/problems/fibonacci-number) (Easy)
47+
1. [N-th Tribonacci Number](https://github.com/openset/leetcode/tree/master/problems/n-th-tribonacci-number) (Easy)
4748

4849
### Hints
4950
<details>

problems/day-of-the-year/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/string-transforms-into-another-string "String Transforms Into Another String")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-dice-rolls-with-target-sum "Number of Dice Rolls With Target Sum")
11+
12+
## 1154. Day of the Year (Easy)
13+
14+
<p>Given a string <code>date</code> representing a <a href="https://en.wikipedia.org/wiki/Gregorian_calendar" target="_blank">Gregorian&nbsp;calendar</a> date formatted as <code>YYYY-MM-DD</code>, return the day number of the year.</p>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> date = &quot;2019-01-09&quot;
21+
<strong>Output:</strong> 9
22+
<strong>Explanation:</strong> Given date is the 9th day of the year in 2019.
23+
</pre>
24+
25+
<p><strong>Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> date = &quot;2019-02-10&quot;
29+
<strong>Output:</strong> 41
30+
</pre>
31+
32+
<p><strong>Example 3:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> date = &quot;2003-03-01&quot;
36+
<strong>Output:</strong> 60
37+
</pre>
38+
39+
<p><strong>Example 4:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> date = &quot;2004-03-01&quot;
43+
<strong>Output:</strong> 61
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
<p><strong>Constraints:</strong></p>
48+
49+
<ul>
50+
<li><code>date.length == 10</code></li>
51+
<li><code>date[4] == date[7] == &#39;-&#39;</code>, and all other <code>date[i]</code>&#39;s are digits</li>
52+
<li><code>date</code> represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.</li>
53+
</ul>

problems/insertion-sort-list/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ With each iteration one element (red) is removed from the input data and inserte
4848
</pre>
4949

5050
### Related Topics
51-
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
5251
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)]
52+
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
5353

5454
### Similar Questions
5555
1. [Sort List](https://github.com/openset/leetcode/tree/master/problems/sort-list) (Medium)

problems/longest-chunked-palindrome-decomposition/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/snapshot-array "Snapshot Array")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/article-views-i "Article Views I")
1111

1212
## 1147. Longest Chunked Palindrome Decomposition (Hard)
1313

problems/longest-consecutive-sequence/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
</pre>
2525

2626
### Related Topics
27-
[[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)]
2827
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
28+
[[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)]
2929

3030
### Similar Questions
3131
1. [Binary Tree Longest Consecutive Sequence](https://github.com/openset/leetcode/tree/master/problems/binary-tree-longest-consecutive-sequence) (Medium)

problems/majority-element-ii/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
### Similar Questions
3434
1. [Majority Element](https://github.com/openset/leetcode/tree/master/problems/majority-element) (Easy)
35+
1. [Check If a Number Is Majority Element in a Sorted Array](https://github.com/openset/leetcode/tree/master/problems/check-if-a-number-is-majority-element-in-a-sorted-array) (Easy)
3536

3637
### Hints
3738
<details>

problems/majority-element/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@
3535

3636
### Similar Questions
3737
1. [Majority Element II](https://github.com/openset/leetcode/tree/master/problems/majority-element-ii) (Medium)
38+
1. [Check If a Number Is Majority Element in a Sorted Array](https://github.com/openset/leetcode/tree/master/problems/check-if-a-number-is-majority-element-in-a-sorted-array) (Easy)

problems/meeting-rooms-ii/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
1. [Merge Intervals](https://github.com/openset/leetcode/tree/master/problems/merge-intervals) (Medium)
2323
1. [Meeting Rooms](https://github.com/openset/leetcode/tree/master/problems/meeting-rooms) (Easy)
2424
1. [Minimum Number of Arrows to Burst Balloons](https://github.com/openset/leetcode/tree/master/problems/minimum-number-of-arrows-to-burst-balloons) (Medium)
25+
1. [Car Pooling](https://github.com/openset/leetcode/tree/master/problems/car-pooling) (Medium)
2526

2627
### Hints
2728
<details>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/check-if-a-number-is-majority-element-in-a-sorted-array "Check If a Number Is Majority Element in a Sorted Array")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/analyze-user-website-visit-pattern "Analyze User Website Visit Pattern")
11+
12+
## 1151. Minimum Swaps to Group All 1's Together (Medium)
13+
14+
15+
16+
### Related Topics
17+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
18+
[[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)]
19+
20+
### Hints
21+
<details>
22+
<summary>Hint 1</summary>
23+
How many 1's should be grouped together ? Is not a fixed number?
24+
</details>
25+
26+
<details>
27+
<summary>Hint 2</summary>
28+
Yeah it's just the number of 1's the whole array has. Let's name this number as ones
29+
</details>
30+
31+
<details>
32+
<summary>Hint 3</summary>
33+
Every subarray of size of ones, needs some number of swaps to reach, Can you find the number of swaps needed to group all 1's in this subarray?
34+
</details>
35+
36+
<details>
37+
<summary>Hint 4</summary>
38+
It's the number of zeros in that subarray.
39+
</details>
40+
41+
<details>
42+
<summary>Hint 5</summary>
43+
Do you need to count the number of zeros all over again for every position ?
44+
</details>
45+
46+
<details>
47+
<summary>Hint 6</summary>
48+
Use Sliding Window technique.
49+
</details>

problems/minimum-window-substring/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
1. [Minimum Size Subarray Sum](https://github.com/openset/leetcode/tree/master/problems/minimum-size-subarray-sum) (Medium)
3939
1. [Sliding Window Maximum](https://github.com/openset/leetcode/tree/master/problems/sliding-window-maximum) (Hard)
4040
1. [Permutation in String](https://github.com/openset/leetcode/tree/master/problems/permutation-in-string) (Medium)
41-
1. [Smallest Range](https://github.com/openset/leetcode/tree/master/problems/smallest-range) (Hard)
4241
1. [Minimum Window Subsequence](https://github.com/openset/leetcode/tree/master/problems/minimum-window-subsequence) (Hard)
4342

4443
### Hints

problems/n-th-tribonacci-number/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ T_4 = 1 + 1 + 2 = 4
4242
<li><code>0 &lt;= n &lt;= 37</code></li>
4343
<li>The answer is guaranteed to fit within a 32-bit integer, ie. <code>answer &lt;= 2^31 - 1</code>.</li>
4444
</ul>
45+
46+
### Similar Questions
47+
1. [Climbing Stairs](https://github.com/openset/leetcode/tree/master/problems/climbing-stairs) (Easy)

0 commit comments

Comments
 (0)