-
Notifications
You must be signed in to change notification settings - Fork 130
A: new #834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
A: new #834
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
problems/ad-free-sessions/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../maximize-number-of-nice-divisors "Maximize Number of Nice Divisors") | ||
|
||
[Next >](../minimum-path-cost-in-a-hidden-grid "Minimum Path Cost in a Hidden Grid") | ||
|
||
## [1809. Ad-Free Sessions (Easy)](https://leetcode.com/problems/ad-free-sessions "") | ||
|
||
|
12 changes: 12 additions & 0 deletions
problems/ad-free-sessions/mysql_schemas.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Create table If Not Exists Playback(session_id int,customer_id int,start_time int,end_time int); | ||
Create table If Not Exists Ads (ad_id int, customer_id int, timestamp int); | ||
Truncate table Playback; | ||
insert into Playback (session_id, customer_id, start_time, end_time) values ('1', '1', '1', '5'); | ||
insert into Playback (session_id, customer_id, start_time, end_time) values ('2', '1', '15', '23'); | ||
insert into Playback (session_id, customer_id, start_time, end_time) values ('3', '2', '10', '12'); | ||
insert into Playback (session_id, customer_id, start_time, end_time) values ('4', '2', '17', '28'); | ||
insert into Playback (session_id, customer_id, start_time, end_time) values ('5', '2', '2', '8'); | ||
Truncate table Ads; | ||
insert into Ads (ad_id, customer_id, timestamp) values ('1', '1', '5'); | ||
insert into Ads (ad_id, customer_id, timestamp) values ('2', '2', '17'); | ||
insert into Ads (ad_id, customer_id, timestamp) values ('3', '2', '20'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
problems/count-nice-pairs-in-an-array/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../sentence-similarity-iii "Sentence Similarity III") | ||
|
||
[Next >](../maximum-number-of-groups-getting-fresh-donuts "Maximum Number of Groups Getting Fresh Donuts") | ||
|
||
## [1814. Count Nice Pairs in an Array (Medium)](https://leetcode.com/problems/count-nice-pairs-in-an-array "统计一个数组中好对子的数目") | ||
|
||
<p>You are given an array <code>nums</code> that consists of non-negative integers. Let us define <code>rev(x)</code> as the reverse of the non-negative integer <code>x</code>. For example, <code>rev(123) = 321</code>, and <code>rev(120) = 21</code>. A pair of indices <code>(i, j)</code> is <strong>nice</strong> if it satisfies all of the following conditions:</p> | ||
|
||
<ul> | ||
<li><code>0 <= i < j < nums.length</code></li> | ||
<li><code>nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])</code></li> | ||
</ul> | ||
|
||
<p>Return <em>the number of nice pairs of indices</em>. Since that number can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [42,11,1,97] | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation:</strong> The two pairs are: | ||
- (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121. | ||
- (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [13,10,35,24,76] | ||
<strong>Output:</strong> 4 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li> | ||
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Array](../../tag/array/README.md)] | ||
[[Hash Table](../../tag/hash-table/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
The condition can be rearranged to (nums[i] - rev(nums[i])) == (nums[j] - rev(nums[j])). | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Transform each nums[i] into (nums[i] - rev(nums[i])). Then, count the number of (i, j) pairs that have equal values. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 3</summary> | ||
Keep a map storing the frequencies of values that you have seen so far. For each i, check if nums[i] is in the map. If it is, then add that count to the overall count. Then, increment the frequency of nums[i]. | ||
</details> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.