From 6d11c3aaa0b7ab68ccbe319cf30f631079dac72e Mon Sep 17 00:00:00 2001 From: Shuo Date: Thu, 13 Feb 2020 09:51:36 +0800 Subject: [PATCH] Add: new --- README.md | 15 +++- .../angle-between-hands-of-a-clock/README.md | 79 +++++++++++++++++ .../check-if-n-and-its-double-exist/README.md | 69 +++++++++++++++ problems/counting-bits/README.md | 2 +- problems/intersection-of-two-arrays/README.md | 2 +- problems/jump-game-iv/README.md | 87 +++++++++++++++++++ problems/jump-game-v/README.md | 2 +- .../README.md | 2 +- .../maximum-students-taking-exam/README.md | 79 +++++++++++++++++ .../README.md | 80 +++++++++++++++++ problems/movie-rating/README.md | 14 +++ problems/movie-rating/mysql_schemas.sql | 22 +++++ .../README.md | 64 ++++++++++++++ .../README.md | 78 +++++++++++++++++ .../README.md | 2 +- .../queries-quality-and-percentage/README.md | 2 +- problems/tweet-counts-per-frequency/README.md | 62 +++++++++++++ .../x-of-a-kind-in-a-deck-of-cards/README.md | 65 +++++--------- tag/array/README.md | 2 + tag/bit-manipulation/README.md | 1 + tag/breadth-first-search/README.md | 1 + tag/design/README.md | 1 + tag/dynamic-programming/README.md | 1 + tag/math/README.md | 1 + tag/string/README.md | 1 + 25 files changed, 683 insertions(+), 51 deletions(-) create mode 100644 problems/angle-between-hands-of-a-clock/README.md create mode 100644 problems/check-if-n-and-its-double-exist/README.md create mode 100644 problems/jump-game-iv/README.md create mode 100644 problems/maximum-students-taking-exam/README.md create mode 100644 problems/minimum-number-of-steps-to-make-two-strings-anagram/README.md create mode 100644 problems/movie-rating/README.md create mode 100644 problems/movie-rating/mysql_schemas.sql create mode 100644 problems/number-of-steps-to-reduce-a-number-to-zero/README.md create mode 100644 problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/README.md create mode 100644 problems/tweet-counts-per-frequency/README.md diff --git a/README.md b/README.md index 02d19b0a3..5f49225c2 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,20 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1349 | [Maximum Students Taking Exam](https://leetcode.com/problems/maximum-students-taking-exam "参加考试的最大学生数") | [Go](problems/maximum-students-taking-exam) | Hard | +| 1348 | [Tweet Counts Per Frequency](https://leetcode.com/problems/tweet-counts-per-frequency "推文计数") | [Go](problems/tweet-counts-per-frequency) | Medium | +| 1347 | [Minimum Number of Steps to Make Two Strings Anagram](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram "制造字母异位词的最小步骤数") | [Go](problems/minimum-number-of-steps-to-make-two-strings-anagram) | Medium | +| 1346 | [Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist "检查整数及其两倍数是否存在") | [Go](problems/check-if-n-and-its-double-exist) | Easy | +| 1345 | [Jump Game IV](https://leetcode.com/problems/jump-game-iv "跳跃游戏 IV") | [Go](problems/jump-game-iv) | Hard | +| 1344 | [Angle Between Hands of a Clock](https://leetcode.com/problems/angle-between-hands-of-a-clock "时钟指针的夹角") | [Go](problems/angle-between-hands-of-a-clock) | Medium | +| 1343 | [Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold](https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold "大小为 K 且平均值大于等于阈值的子数组数目") | [Go](problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold) | Medium | +| 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero "将数字变成 0 的操作次数") | [Go](problems/number-of-steps-to-reduce-a-number-to-zero) | Easy | +| 1341 | [Movie Rating](https://leetcode.com/problems/movie-rating "电影评分") 🔒 | [MySQL](problems/movie-rating) | Medium | | 1340 | [Jump Game V](https://leetcode.com/problems/jump-game-v "跳跃游戏 V") | [Go](problems/jump-game-v) | Hard | | 1339 | [Maximum Product of Splitted Binary Tree](https://leetcode.com/problems/maximum-product-of-splitted-binary-tree "分裂二叉树的最大乘积") | [Go](problems/maximum-product-of-splitted-binary-tree) | Medium | | 1338 | [Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half "数组大小减半") | [Go](problems/reduce-array-size-to-the-half) | Medium | | 1337 | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix "方阵中战斗力最弱的 K 行") | [Go](problems/the-k-weakest-rows-in-a-matrix) | Easy | -| 1336 | [Number of Transactions per Visit](https://leetcode.com/problems/number-of-transactions-per-visit) 🔒 | [MySQL](problems/number-of-transactions-per-visit) | Medium | +| 1336 | [Number of Transactions per Visit](https://leetcode.com/problems/number-of-transactions-per-visit) 🔒 | [MySQL](problems/number-of-transactions-per-visit) | Hard | | 1335 | [Minimum Difficulty of a Job Schedule](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule "工作计划的最低难度") | [Go](problems/minimum-difficulty-of-a-job-schedule) | Hard | | 1334 | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance "阈值距离内邻居最少的城市") | [Go](problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance) | Medium | | 1333 | [Filter Restaurants by Vegan-Friendly, Price and Distance](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance "餐厅过滤器") | [Go](problems/filter-restaurants-by-vegan-friendly-price-and-distance) | Medium | @@ -191,14 +200,14 @@ LeetCode Problems' Solutions | 1214 | [Two Sum BSTs](https://leetcode.com/problems/two-sum-bsts "查找两棵二叉搜索树之和") 🔒 | [Go](problems/two-sum-bsts) | Medium | | 1213 | [Intersection of Three Sorted Arrays](https://leetcode.com/problems/intersection-of-three-sorted-arrays "三个有序数组的交集") 🔒 | [Go](problems/intersection-of-three-sorted-arrays) | Easy | | 1212 | [Team Scores in Football Tournament](https://leetcode.com/problems/team-scores-in-football-tournament "查询球队积分") 🔒 | [MySQL](problems/team-scores-in-football-tournament) | Medium | -| 1211 | [Queries Quality and Percentage](https://leetcode.com/problems/queries-quality-and-percentage) 🔒 | [MySQL](problems/queries-quality-and-percentage) | Easy | +| 1211 | [Queries Quality and Percentage](https://leetcode.com/problems/queries-quality-and-percentage "查询结果的质量和占比") 🔒 | [MySQL](problems/queries-quality-and-percentage) | Easy | | 1210 | [Minimum Moves to Reach Target with Rotations](https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations "穿过迷宫的最少移动次数") | [Go](problems/minimum-moves-to-reach-target-with-rotations) | Hard | | 1209 | [Remove All Adjacent Duplicates in String II](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii "删除字符串中的所有相邻重复项 II") | [Go](problems/remove-all-adjacent-duplicates-in-string-ii) | Medium | | 1208 | [Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget "尽可能使字符串相等") | [Go](problems/get-equal-substrings-within-budget) | Medium | | 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences "独一无二的出现次数") | [Go](problems/unique-number-of-occurrences) | Easy | | 1206 | [Design Skiplist](https://leetcode.com/problems/design-skiplist "设计跳表") | [Go](problems/design-skiplist) | Hard | | 1205 | [Monthly Transactions II](https://leetcode.com/problems/monthly-transactions-ii "每月交易II") 🔒 | [MySQL](problems/monthly-transactions-ii) | Medium | -| 1204 | [Last Person to Fit in the Elevator](https://leetcode.com/problems/last-person-to-fit-in-the-elevator) 🔒 | [MySQL](problems/last-person-to-fit-in-the-elevator) | Medium | +| 1204 | [Last Person to Fit in the Elevator](https://leetcode.com/problems/last-person-to-fit-in-the-elevator "最后一个能进入电梯的人") 🔒 | [MySQL](problems/last-person-to-fit-in-the-elevator) | Medium | | 1203 | [Sort Items by Groups Respecting Dependencies](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies "项目管理") | [Go](problems/sort-items-by-groups-respecting-dependencies) | Hard | | 1202 | [Smallest String With Swaps](https://leetcode.com/problems/smallest-string-with-swaps "交换字符串中的元素") | [Go](problems/smallest-string-with-swaps) | Medium | | 1201 | [Ugly Number III](https://leetcode.com/problems/ugly-number-iii "丑数 III") | [Go](problems/ugly-number-iii) | Medium | diff --git a/problems/angle-between-hands-of-a-clock/README.md b/problems/angle-between-hands-of-a-clock/README.md new file mode 100644 index 000000000..b78b0d9d9 --- /dev/null +++ b/problems/angle-between-hands-of-a-clock/README.md @@ -0,0 +1,79 @@ + + + + + + + +[< Previous](../number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold "Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold") +                 +[Next >](../jump-game-iv "Jump Game IV") + +## [1344. Angle Between Hands of a Clock (Medium)](https://leetcode.com/problems/angle-between-hands-of-a-clock "时钟指针的夹角") + +

Given two numbers, hour and minutes. Return the smaller angle (in sexagesimal units) formed between the hour and the minute hand.

+ +

 

+

Example 1:

+ +

+ +
+Input: hour = 12, minutes = 30
+Output: 165
+
+ +

Example 2:

+ +

+ +
+Input: hour = 3, minutes = 30
+Output: 75
+
+ +

Example 3:

+ +

+ +
+Input: hour = 3, minutes = 15
+Output: 7.5
+
+ +

Example 4:

+ +
+Input: hour = 4, minutes = 50
+Output: 155
+
+ +

Example 5:

+ +
+Input: hour = 12, minutes = 0
+Output: 0
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Math](../../tag/math/README.md)] + +### Hints +
+Hint 1 +The tricky part is determining how the minute hand affects the position of the hour hand. +
+ +
+Hint 2 +Calculate the angles separately then find the difference. +
diff --git a/problems/check-if-n-and-its-double-exist/README.md b/problems/check-if-n-and-its-double-exist/README.md new file mode 100644 index 000000000..f0125d228 --- /dev/null +++ b/problems/check-if-n-and-its-double-exist/README.md @@ -0,0 +1,69 @@ + + + + + + + +[< Previous](../jump-game-iv "Jump Game IV") +                 +[Next >](../minimum-number-of-steps-to-make-two-strings-anagram "Minimum Number of Steps to Make Two Strings Anagram") + +## [1346. Check If N and Its Double Exist (Easy)](https://leetcode.com/problems/check-if-n-and-its-double-exist "检查整数及其两倍数是否存在") + +

Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M).

+ +

More formally check if there exists two indices i and j such that :

+ + + +

 

+

Example 1:

+ +
+Input: arr = [10,2,5,3]
+Output: true
+Explanation: N = 10 is the double of M = 5,that is, 10 = 2 * 5.
+
+ +

Example 2:

+ +
+Input: arr = [7,1,14,11]
+Output: true
+Explanation: N = 14 is the double of M = 7,that is, 14 = 2 * 7.
+
+ +

Example 3:

+ +
+Input: arr = [3,1,7,11]
+Output: false
+Explanation: In this case does not exist N and M, such that N = 2 * M.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Array](../../tag/array/README.md)] + +### Hints +
+Hint 1 +Loop from i = 0 to arr.length, maintaining in a hashTable the array elements from [0, i - 1]. +
+ +
+Hint 2 +On each step of the loop check if we have seen the element 2 * arr[i] so far or arr[i] / 2 was seen if arr[i] % 2 == 0. +
diff --git a/problems/counting-bits/README.md b/problems/counting-bits/README.md index e8d6a286b..9169d1a68 100644 --- a/problems/counting-bits/README.md +++ b/problems/counting-bits/README.md @@ -35,8 +35,8 @@ ### Related Topics - [[Bit Manipulation](../../tag/bit-manipulation/README.md)] [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + [[Bit Manipulation](../../tag/bit-manipulation/README.md)] ### Similar Questions 1. [Number of 1 Bits](../number-of-1-bits) (Easy) diff --git a/problems/intersection-of-two-arrays/README.md b/problems/intersection-of-two-arrays/README.md index 09355375f..26f036111 100644 --- a/problems/intersection-of-two-arrays/README.md +++ b/problems/intersection-of-two-arrays/README.md @@ -38,10 +38,10 @@

 

### Related Topics - [[Sort](../../tag/sort/README.md)] [[Hash Table](../../tag/hash-table/README.md)] [[Two Pointers](../../tag/two-pointers/README.md)] [[Binary Search](../../tag/binary-search/README.md)] + [[Sort](../../tag/sort/README.md)] ### Similar Questions 1. [Intersection of Two Arrays II](../intersection-of-two-arrays-ii) (Easy) diff --git a/problems/jump-game-iv/README.md b/problems/jump-game-iv/README.md new file mode 100644 index 000000000..1e5d81d6d --- /dev/null +++ b/problems/jump-game-iv/README.md @@ -0,0 +1,87 @@ + + + + + + + +[< Previous](../angle-between-hands-of-a-clock "Angle Between Hands of a Clock") +                 +[Next >](../check-if-n-and-its-double-exist "Check If N and Its Double Exist") + +## [1345. Jump Game IV (Hard)](https://leetcode.com/problems/jump-game-iv "跳跃游戏 IV") + +

Given an array of integers arr, you are initially positioned at the first index of the array.

+ +

In one step you can jump from index i to index:

+ + + +

Return the minimum number of steps to reach the last index of the array.

+ +

Notice that you can not jump outside of the array at any time.

+ +

 

+

Example 1:

+ +
+Input: arr = [100,-23,-23,404,100,23,23,23,3,404]
+Output: 3
+Explanation: You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.
+
+ +

Example 2:

+ +
+Input: arr = [7]
+Output: 0
+Explanation: Start index is the last index. You don't need to jump.
+
+ +

Example 3:

+ +
+Input: arr = [7,6,9,6,9,6,9,7]
+Output: 1
+Explanation: You can jump directly from index 0 to index 7 which is last index of the array.
+
+ +

Example 4:

+ +
+Input: arr = [6,1,9]
+Output: 2
+
+ +

Example 5:

+ +
+Input: arr = [11,22,7,7,7,7,7,7,7,22,13]
+Output: 3
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Breadth-first Search](../../tag/breadth-first-search/README.md)] + +### Hints +
+Hint 1 +Build a graph of n nodes where nodes are the indices of the array and edges for node i are nodes i+1, i-1, j where arr[i] == arr[j]. +
+ +
+Hint 2 +Start bfs from node 0 and keep distance, answer is the distance when you reach onode n-1. +
diff --git a/problems/jump-game-v/README.md b/problems/jump-game-v/README.md index b30bfe79c..177bf0404 100644 --- a/problems/jump-game-v/README.md +++ b/problems/jump-game-v/README.md @@ -7,7 +7,7 @@ [< Previous](../maximum-product-of-splitted-binary-tree "Maximum Product of Splitted Binary Tree")                  -Next > +[Next >](../movie-rating "Movie Rating") ## [1340. Jump Game V (Hard)](https://leetcode.com/problems/jump-game-v "跳跃游戏 V") diff --git a/problems/last-person-to-fit-in-the-elevator/README.md b/problems/last-person-to-fit-in-the-elevator/README.md index bb8211854..0d8f8558c 100644 --- a/problems/last-person-to-fit-in-the-elevator/README.md +++ b/problems/last-person-to-fit-in-the-elevator/README.md @@ -9,7 +9,7 @@                  [Next >](../monthly-transactions-ii "Monthly Transactions II") -## [1204. Last Person to Fit in the Elevator (Medium)](https://leetcode.com/problems/last-person-to-fit-in-the-elevator "") +## [1204. Last Person to Fit in the Elevator (Medium)](https://leetcode.com/problems/last-person-to-fit-in-the-elevator "最后一个能进入电梯的人")

Table: Queue

diff --git a/problems/maximum-students-taking-exam/README.md b/problems/maximum-students-taking-exam/README.md new file mode 100644 index 000000000..42528f4fb --- /dev/null +++ b/problems/maximum-students-taking-exam/README.md @@ -0,0 +1,79 @@ + + + + + + + +[< Previous](../tweet-counts-per-frequency "Tweet Counts Per Frequency") +                 +Next > + +## [1349. Maximum Students Taking Exam (Hard)](https://leetcode.com/problems/maximum-students-taking-exam "参加考试的最大学生数") + +

Given a m * n matrix seats  that represent seats distributions in a classroom. If a seat is broken, it is denoted by '#' character otherwise it is denoted by a '.' character.

+ +

Students can see the answers of those sitting next to the left, right, upper left and upper right, but he cannot see the answers of the student sitting directly in front or behind him. Return the maximum number of students that can take the exam together without any cheating being possible..

+ +

Students must be placed in seats in good condition.

+ +

 

+

Example 1:

+ +
+Input: seats = [["#",".","#","#",".","#"],
+                [".","#","#","#","#","."],
+                ["#",".","#","#",".","#"]]
+Output: 4
+Explanation: Teacher can place 4 students in available seats so they don't cheat on the exam. 
+
+ +

Example 2:

+ +
+Input: seats = [[".","#"],
+                ["#","#"],
+                ["#","."],
+                ["#","#"],
+                [".","#"]]
+Output: 3
+Explanation: Place all students in available seats. 
+
+
+ +

Example 3:

+ +
+Input: seats = [["#",".",".",".","#"],
+                [".","#",".","#","."],
+                [".",".","#",".","."],
+                [".","#",".","#","."],
+                ["#",".",".",".","#"]]
+Output: 10
+Explanation: Place students in available seats in column 1, 3 and 5.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +Students in row i only can see exams in row i+1. +
+ +
+Hint 2 +Use Dynamic programming to compute the result given a (current row, bitmask people seated in previous row). +
diff --git a/problems/minimum-number-of-steps-to-make-two-strings-anagram/README.md b/problems/minimum-number-of-steps-to-make-two-strings-anagram/README.md new file mode 100644 index 000000000..6923d359f --- /dev/null +++ b/problems/minimum-number-of-steps-to-make-two-strings-anagram/README.md @@ -0,0 +1,80 @@ + + + + + + + +[< Previous](../check-if-n-and-its-double-exist "Check If N and Its Double Exist") +                 +[Next >](../tweet-counts-per-frequency "Tweet Counts Per Frequency") + +## [1347. Minimum Number of Steps to Make Two Strings Anagram (Medium)](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram "制造字母异位词的最小步骤数") + +

Given two equal-size strings s and t. In one step you can choose any character of t and replace it with another character.

+ +

Return the minimum number of steps to make t an anagram of s.

+ +

An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.

+ +

 

+

Example 1:

+ +
+Input: s = "bab", t = "aba"
+Output: 1
+Explanation: Replace the first 'a' in t with b, t = "bba" which is anagram of s.
+
+ +

Example 2:

+ +
+Input: s = "leetcode", t = "practice"
+Output: 5
+Explanation: Replace 'p', 'r', 'a', 'i' and 'c' from t with proper characters to make t anagram of s.
+
+ +

Example 3:

+ +
+Input: s = "anagram", t = "mangaar"
+Output: 0
+Explanation: "anagram" and "mangaar" are anagrams. 
+
+ +

Example 4:

+ +
+Input: s = "xxyyzz", t = "xxyyzz"
+Output: 0
+
+ +

Example 5:

+ +
+Input: s = "friend", t = "family"
+Output: 4
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[String](../../tag/string/README.md)] + +### Hints +
+Hint 1 +Count the frequency of characters of each string. +
+ +
+Hint 2 +Loop over all characters if the frequency of a character in t is less than the frequency of the same character in s then add the difference between the frequencies to the answer. +
diff --git a/problems/movie-rating/README.md b/problems/movie-rating/README.md new file mode 100644 index 000000000..7d825c727 --- /dev/null +++ b/problems/movie-rating/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](../jump-game-v "Jump Game V") +                 +[Next >](../number-of-steps-to-reduce-a-number-to-zero "Number of Steps to Reduce a Number to Zero") + +## [1341. Movie Rating (Medium)](https://leetcode.com/problems/movie-rating "电影评分") + + diff --git a/problems/movie-rating/mysql_schemas.sql b/problems/movie-rating/mysql_schemas.sql new file mode 100644 index 000000000..03c2afee1 --- /dev/null +++ b/problems/movie-rating/mysql_schemas.sql @@ -0,0 +1,22 @@ +Create table If Not Exists Movies (movie_id int, title varchar(30)); +Create table If Not Exists Users (user_id int, name varchar(30)); +Create table If Not Exists Movie_Rating (movie_id int, user_id int, rating int, created_at date); +Truncate table Movies; +insert into Movies (movie_id, title) values ('1', 'Avengers'); +insert into Movies (movie_id, title) values ('2', 'Frozen 2'); +insert into Movies (movie_id, title) values ('3', 'Joker'); +Truncate table Users; +insert into Users (user_id, name) values ('1', 'Daniel'); +insert into Users (user_id, name) values ('2', 'Monica'); +insert into Users (user_id, name) values ('3', 'Maria'); +insert into Users (user_id, name) values ('4', 'James'); +Truncate table Movie_Rating; +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('1', '1', '3', '2020-01-12'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('1', '2', '4', '2020-02-11'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('1', '3', '2', '2020-02-12'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('1', '4', '1', '2020-01-01'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('2', '1', '5', '2020-02-17'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('2', '2', '2', '2020-02-01'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('2', '3', '2', '2020-03-01'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('3', '1', '3', '2020-02-22'); +insert into Movie_Rating (movie_id, user_id, rating, created_at) values ('3', '2', '4', '2020-02-25'); diff --git a/problems/number-of-steps-to-reduce-a-number-to-zero/README.md b/problems/number-of-steps-to-reduce-a-number-to-zero/README.md new file mode 100644 index 000000000..e32d8d282 --- /dev/null +++ b/problems/number-of-steps-to-reduce-a-number-to-zero/README.md @@ -0,0 +1,64 @@ + + + + + + + +[< Previous](../movie-rating "Movie Rating") +                 +[Next >](../number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold "Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold") + +## [1342. Number of Steps to Reduce a Number to Zero (Easy)](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero "将数字变成 0 的操作次数") + +

Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.

+ +

 

+

Example 1:

+ +
+Input: num = 14
+Output: 6
+Explanation: 
+Step 1) 14 is even; divide by 2 and obtain 7. 
+Step 2) 7 is odd; subtract 1 and obtain 6.
+Step 3) 6 is even; divide by 2 and obtain 3. 
+Step 4) 3 is odd; subtract 1 and obtain 2. 
+Step 5) 2 is even; divide by 2 and obtain 1. 
+Step 6) 1 is odd; subtract 1 and obtain 0.
+
+ +

Example 2:

+ +
+Input: num = 8
+Output: 4
+Explanation: 
+Step 1) 8 is even; divide by 2 and obtain 4. 
+Step 2) 4 is even; divide by 2 and obtain 2. 
+Step 3) 2 is even; divide by 2 and obtain 1. 
+Step 4) 1 is odd; subtract 1 and obtain 0.
+
+ +

Example 3:

+ +
+Input: num = 123
+Output: 12
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Bit Manipulation](../../tag/bit-manipulation/README.md)] + +### Hints +
+Hint 1 +Simulate the process to get the final answer. +
diff --git a/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/README.md b/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/README.md new file mode 100644 index 000000000..8049a016c --- /dev/null +++ b/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/README.md @@ -0,0 +1,78 @@ + + + + + + + +[< Previous](../number-of-steps-to-reduce-a-number-to-zero "Number of Steps to Reduce a Number to Zero") +                 +[Next >](../angle-between-hands-of-a-clock "Angle Between Hands of a Clock") + +## [1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold (Medium)](https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold "大小为 K 且平均值大于等于阈值的子数组数目") + +

Given an array of integers arr and two integers k and threshold.

+ +

Return the number of sub-arrays of size k and average greater than or equal to threshold.

+ +

 

+

Example 1:

+ +
+Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
+Output: 3
+Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold).
+
+ +

Example 2:

+ +
+Input: arr = [1,1,1,1,1], k = 1, threshold = 0
+Output: 5
+
+ +

Example 3:

+ +
+Input: arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5
+Output: 6
+Explanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers.
+
+ +

Example 4:

+ +
+Input: arr = [7,7,7,7,7,7,7], k = 7, threshold = 7
+Output: 1
+
+ +

Example 5:

+ +
+Input: arr = [4,4,4,4], k = 4, threshold = 1
+Output: 1
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Array](../../tag/array/README.md)] + +### Hints +
+Hint 1 +Start with a window of size K and test its average against the threshold. +
+ +
+Hint 2 +Keep moving the window by one element maintaining its size k until you cover the whole array. count number of windows that satisfy that its average is greater than the threshold. +
diff --git a/problems/number-of-transactions-per-visit/README.md b/problems/number-of-transactions-per-visit/README.md index f730c2508..fce4ce6f3 100644 --- a/problems/number-of-transactions-per-visit/README.md +++ b/problems/number-of-transactions-per-visit/README.md @@ -9,7 +9,7 @@                  [Next >](../the-k-weakest-rows-in-a-matrix "The K Weakest Rows in a Matrix") -## [1336. Number of Transactions per Visit (Medium)](https://leetcode.com/problems/number-of-transactions-per-visit "") +## [1336. Number of Transactions per Visit (Hard)](https://leetcode.com/problems/number-of-transactions-per-visit "")

Table: Visits

diff --git a/problems/queries-quality-and-percentage/README.md b/problems/queries-quality-and-percentage/README.md
index 508c9449b..8d7f56944 100644
--- a/problems/queries-quality-and-percentage/README.md
+++ b/problems/queries-quality-and-percentage/README.md
@@ -9,7 +9,7 @@
                 
 [Next >](../team-scores-in-football-tournament "Team Scores in Football Tournament")
 
-## [1211. Queries Quality and Percentage (Easy)](https://leetcode.com/problems/queries-quality-and-percentage "")
+## [1211. Queries Quality and Percentage (Easy)](https://leetcode.com/problems/queries-quality-and-percentage "查询结果的质量和占比")
 
 

Table: Queries

diff --git a/problems/tweet-counts-per-frequency/README.md b/problems/tweet-counts-per-frequency/README.md new file mode 100644 index 000000000..5c1992a42 --- /dev/null +++ b/problems/tweet-counts-per-frequency/README.md @@ -0,0 +1,62 @@ + + + + + + + +[< Previous](../minimum-number-of-steps-to-make-two-strings-anagram "Minimum Number of Steps to Make Two Strings Anagram") +                 +[Next >](../maximum-students-taking-exam "Maximum Students Taking Exam") + +## [1348. Tweet Counts Per Frequency (Medium)](https://leetcode.com/problems/tweet-counts-per-frequency "推文计数") + +

Implement the class TweetCounts that supports two methods:

+ +

1. recordTweet(string tweetName, int time)

+ + + +

2. getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime)

+ + + +

 

+

Example:

+ +
+Input
+["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency","recordTweet","getTweetCountsPerFrequency"]
+[[],["tweet3",0],["tweet3",60],["tweet3",10],["minute","tweet3",0,59],["minute","tweet3",0,60],["tweet3",120],["hour","tweet3",0,210]]
+
+Output
+[null,null,null,null,[2],[2,1],null,[4]]
+
+Explanation
+TweetCounts tweetCounts = new TweetCounts();
+tweetCounts.recordTweet("tweet3", 0);
+tweetCounts.recordTweet("tweet3", 60);
+tweetCounts.recordTweet("tweet3", 10);                             // All tweets correspond to "tweet3" with recorded times at 0, 10 and 60.
+tweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); // return [2]. The frequency is per minute (60 seconds), so there is one interval of time: 1) [0, 60> - > 2 tweets.
+tweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); // return [2, 1]. The frequency is per minute (60 seconds), so there are two intervals of time: 1) [0, 60> - > 2 tweets, and 2) [60,61> - > 1 tweet.
+tweetCounts.recordTweet("tweet3", 120);                            // All tweets correspond to "tweet3" with recorded times at 0, 10, 60 and 120.
+tweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210);  // return [4]. The frequency is per hour (3600 seconds), so there is one interval of time: 1) [0, 211> - > 4 tweets.
+
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Design](../../tag/design/README.md)] diff --git a/problems/x-of-a-kind-in-a-deck-of-cards/README.md b/problems/x-of-a-kind-in-a-deck-of-cards/README.md index 5ae7dfdea..2cb334781 100644 --- a/problems/x-of-a-kind-in-a-deck-of-cards/README.md +++ b/problems/x-of-a-kind-in-a-deck-of-cards/README.md @@ -21,72 +21,53 @@

 

-

Example 1:

-Input: [1,2,3,4,4,3,2,1]
-Output: true
-Explanation: Possible partition [1,1],[2,2],[3,3],[4,4]
+Input: deck = [1,2,3,4,4,3,2,1]
+Output: true
+Explanation: Possible partition [1,1],[2,2],[3,3],[4,4].
 
-

Example 2:

-Input: [1,1,1,2,2,2,3,3]
-Output: false
-Explanation: No possible partition.
+Input: deck = [1,1,1,2,2,2,3,3]
+Output: false´
+Explanation: No possible partition.
 
-

Example 3:

-Input: [1]
-Output: false
-Explanation: No possible partition.
+Input: deck = [1]
+Output: false
+Explanation: No possible partition.
 
-

Example 4:

-Input: [1,1]
-Output: true
-Explanation: Possible partition [1,1]
+Input: deck = [1,1]
+Output: true
+Explanation: Possible partition [1,1].
 
-

Example 5:

-Input: [1,1,2,2,2,2]
-Output: true
-Explanation: Possible partition [1,1],[2,2],[2,2]
+Input: deck = [1,1,2,2,2,2]
+Output: true
+Explanation: Possible partition [1,1],[2,2],[2,2].
 
-
-
-
-
- -


-Note:

- -
    -
  1. 1 <= deck.length <= 10000
  2. -
  3. 0 <= deck[i] < 10000
  4. -
- -
-
-
-
-
 
-
-
-
-
+ +

 

+

Constraints:

+ + ### Related Topics [[Array](../../tag/array/README.md)] diff --git a/tag/array/README.md b/tag/array/README.md index a5f55a21f..9db12f938 100644 --- a/tag/array/README.md +++ b/tag/array/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1346 | [检查整数及其两倍数是否存在](../../problems/check-if-n-and-its-double-exist) | [[数组](../array/README.md)] | Easy | +| 1343 | [大小为 K 且平均值大于等于阈值的子数组数目](../../problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold) | [[数组](../array/README.md)] | Medium | | 1338 | [数组大小减半](../../problems/reduce-array-size-to-the-half) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Medium | | 1337 | [方阵中战斗力最弱的 K 行](../../problems/the-k-weakest-rows-in-a-matrix) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Easy | | 1333 | [餐厅过滤器](../../problems/filter-restaurants-by-vegan-friendly-price-and-distance) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | diff --git a/tag/bit-manipulation/README.md b/tag/bit-manipulation/README.md index 560688625..9b9b4004c 100644 --- a/tag/bit-manipulation/README.md +++ b/tag/bit-manipulation/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1342 | [将数字变成 0 的操作次数](../../problems/number-of-steps-to-reduce-a-number-to-zero) | [[位运算](../bit-manipulation/README.md)] | Easy | | 1318 | [或运算的最小翻转次数](../../problems/minimum-flips-to-make-a-or-b-equal-to-c) | [[位运算](../bit-manipulation/README.md)] | Medium | | 1310 | [子数组异或查询](../../problems/xor-queries-of-a-subarray) | [[位运算](../bit-manipulation/README.md)] | Medium | | 1297 | [子串的最大出现次数](../../problems/maximum-number-of-occurrences-of-a-substring) | [[位运算](../bit-manipulation/README.md)] [[字符串](../string/README.md)] | Medium | diff --git a/tag/breadth-first-search/README.md b/tag/breadth-first-search/README.md index cfd690bd3..3b09315e2 100644 --- a/tag/breadth-first-search/README.md +++ b/tag/breadth-first-search/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1345 | [跳跃游戏 IV](../../problems/jump-game-iv) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 1319 | [连通网络的操作次数](../../problems/number-of-operations-to-make-network-connected) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | | 1311 | [获取你好友已观看的视频](../../problems/get-watched-videos-by-your-friends) | [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Medium | | 1306 | [跳跃游戏 III](../../problems/jump-game-iii) | [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | diff --git a/tag/design/README.md b/tag/design/README.md index 18652a73b..05840b149 100644 --- a/tag/design/README.md +++ b/tag/design/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1348 | [推文计数](../../problems/tweet-counts-per-frequency) | [[设计](../design/README.md)] | Medium | | 1286 | [字母组合迭代器](../../problems/iterator-for-combination) | [[设计](../design/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 1244 | [力扣排行榜](../../problems/design-a-leaderboard) 🔒 | [[排序](../sort/README.md)] [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1206 | [设计跳表](../../problems/design-skiplist) | [[设计](../design/README.md)] | Hard | diff --git a/tag/dynamic-programming/README.md b/tag/dynamic-programming/README.md index ef7346fa4..da437ed7f 100644 --- a/tag/dynamic-programming/README.md +++ b/tag/dynamic-programming/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1349 | [参加考试的最大学生数](../../problems/maximum-students-taking-exam) | [[动态规划](../dynamic-programming/README.md)] | Hard | | 1340 | [跳跃游戏 V](../../problems/jump-game-v) | [[动态规划](../dynamic-programming/README.md)] | Hard | | 1339 | [分裂二叉树的最大乘积](../../problems/maximum-product-of-splitted-binary-tree) | [[树](../tree/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1335 | [工作计划的最低难度](../../problems/minimum-difficulty-of-a-job-schedule) | [[动态规划](../dynamic-programming/README.md)] | Hard | diff --git a/tag/math/README.md b/tag/math/README.md index bf444c7fc..980532490 100644 --- a/tag/math/README.md +++ b/tag/math/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1344 | [时钟指针的夹角](../../problems/angle-between-hands-of-a-clock) | [[数学](../math/README.md)] | Medium | | 1330 | [翻转子数组得到最大的数组值](../../problems/reverse-subarray-to-maximize-array-value) | [[数组](../array/README.md)] [[数学](../math/README.md)] | Hard | | 1323 | [6 和 9 组成的最大数字](../../problems/maximum-69-number) | [[数学](../math/README.md)] | Easy | | 1317 | [将整数转换为两个无零整数的和](../../problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [[数学](../math/README.md)] | Easy | diff --git a/tag/string/README.md b/tag/string/README.md index 56d5bf36b..a50d6891a 100644 --- a/tag/string/README.md +++ b/tag/string/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1347 | [制造字母异位词的最小步骤数](../../problems/minimum-number-of-steps-to-make-two-strings-anagram) | [[字符串](../string/README.md)] | Medium | | 1332 | [删除回文子序列](../../problems/remove-palindromic-subsequences) | [[字符串](../string/README.md)] | Easy | | 1328 | [破坏回文串](../../problems/break-a-palindrome) | [[字符串](../string/README.md)] | Medium | | 1324 | [竖直打印单词](../../problems/print-words-vertically) | [[字符串](../string/README.md)] | Medium |