From 91c11c00ab6612978d3dc0e4052e41e3f7899745 Mon Sep 17 00:00:00 2001 From: openset Date: Mon, 24 Jun 2019 17:15:54 +0800 Subject: [PATCH] Add: new --- README.md | 4 + problems/brace-expansion-ii/README.md | 78 +++++++++++++++++++ problems/car-pooling/README.md | 73 +++++++++++++++++ problems/find-in-mountain-array/README.md | 65 ++++++++++++++++ .../shortest-common-supersequence/README.md | 2 +- .../statistics-from-a-large-sample/README.md | 51 ++++++++++++ tag/math/README.md | 1 + tag/two-pointers/README.md | 1 + 8 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 problems/brace-expansion-ii/README.md create mode 100644 problems/car-pooling/README.md create mode 100644 problems/find-in-mountain-array/README.md create mode 100644 problems/statistics-from-a-large-sample/README.md diff --git a/README.md b/README.md index 5481d0fbb..67163fcfc 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1096 | [Brace Expansion II](https://leetcode.com/problems/brace-expansion-ii "花括号展开 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/brace-expansion-ii) | Hard | +| 1095 | [Find in Mountain Array](https://leetcode.com/problems/find-in-mountain-array "山脉数组中查找目标值") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array) | Hard | +| 1094 | [Car Pooling](https://leetcode.com/problems/car-pooling "拼车") | [Go](https://github.com/openset/leetcode/tree/master/problems/car-pooling) | Medium | +| 1093 | [Statistics from a Large Sample](https://leetcode.com/problems/statistics-from-a-large-sample "大样本统计") | [Go](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample) | Medium | | 1092 | [Shortest Common Supersequence](https://leetcode.com/problems/shortest-common-supersequence "最短公共超序列") | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-common-supersequence) | Hard | | 1091 | [Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix "二进制矩阵中的最短路径") | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-path-in-binary-matrix) | Medium | | 1090 | [Largest Values From Labels](https://leetcode.com/problems/largest-values-from-labels "受标签影响的最大值") | [Go](https://github.com/openset/leetcode/tree/master/problems/largest-values-from-labels) | Medium | diff --git a/problems/brace-expansion-ii/README.md b/problems/brace-expansion-ii/README.md new file mode 100644 index 000000000..ef019ad72 --- /dev/null +++ b/problems/brace-expansion-ii/README.md @@ -0,0 +1,78 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array "Find in Mountain Array") +                 +Next > + +## 1096. Brace Expansion II (Hard) + +

Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents.

+ +

Grammar can best be understood through simple examples:

+ + + +

Formally, the 3 rules for our grammar:

+ + + +

Given an expression representing a set of words under the given grammar, return the sorted list of words that the expression represents.

+ +

 

+ +
+

Example 1:

+ +
+Input: "{a,b}{c{d,e}}"
+Output: ["acd","ace","bcd","bce"]
+
+ +
+

Example 2:

+ +
+Input: "{{a,z},a{b,c},{ab,z}}"
+Output: ["a","ab","ac","z"]
+Explanation: Each distinct word is written only once in the final answer.
+
+ +

 

+ +

Constraints:

+ +
    +
  1. 1 <= expression.length <= 50
  2. +
  3. expression[i] consists of '{', '}', ','or lowercase English letters.
  4. +
  5. The given expression represents a set of words based on the grammar given in the description.
  6. +
+
+
diff --git a/problems/car-pooling/README.md b/problems/car-pooling/README.md new file mode 100644 index 000000000..71bd15e9f --- /dev/null +++ b/problems/car-pooling/README.md @@ -0,0 +1,73 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample "Statistics from a Large Sample") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array "Find in Mountain Array") + +## 1094. Car Pooling (Medium) + +

You are driving a vehicle that has capacity empty seats initially available for passengers.  The vehicle only drives east (ie. it cannot turn around and drive west.)

+ +

Given a list of trips, trip[i] = [num_passengers, start_location, end_location] contains information about the i-th trip: the number of passengers that must be picked up, and the locations to pick them up and drop them off.  The locations are given as the number of kilometers due east from your vehicle's initial location.

+ +

Return true if and only if it is possible to pick up and drop off all passengers for all the given trips. 

+ +

 

+ +

Example 1:

+ +
+Input: trips = [[2,1,5],[3,3,7]], capacity = 4
+Output: false
+
+ +
+

Example 2:

+ +
+Input: trips = [[2,1,5],[3,3,7]], capacity = 5
+Output: true
+
+ +
+

Example 3:

+ +
+Input: trips = [[2,1,5],[3,5,7]], capacity = 3
+Output: true
+
+ +
+

Example 4:

+ +
+Input: trips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11
+Output: true
+
+
+
+
+ +
+
+
+
 
+
+
+
+ +

 

+

Constraints:

+ +
    +
  1. trips.length <= 1000
  2. +
  3. trips[i].length == 3
  4. +
  5. 1 <= trips[i][0] <= 100
  6. +
  7. 0 <= trips[i][1] < trips[i][2] <= 1000
  8. +
  9. 1 <= capacity <= 100000
  10. +
diff --git a/problems/find-in-mountain-array/README.md b/problems/find-in-mountain-array/README.md new file mode 100644 index 000000000..4cdf1aa67 --- /dev/null +++ b/problems/find-in-mountain-array/README.md @@ -0,0 +1,65 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/car-pooling "Car Pooling") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/brace-expansion-ii "Brace Expansion II") + +## 1095. Find in Mountain Array (Hard) + +

(This problem is an interactive problem.)

+ +

You may recall that an array A is a mountain array if and only if:

+ + + +

Given a mountain array mountainArr, return the minimum index such that mountainArr.get(index) == target.  If such an index doesn't exist, return -1.

+ +

You can't access the mountain array directly.  You may only access the array using a MountainArray interface:

+ + + +

Submissions making more than 100 calls to MountainArray.get will be judged Wrong Answer.  Also, any solutions that attempt to circumvent the judge will result in disqualification.

+ +
    +
+ +

 

+

Example 1:

+ +
+Input: array = [1,2,3,4,5,3,1], target = 3
+Output: 2
+Explanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.
+ +

Example 2:

+ +
+Input: array = [0,1,2,4,2,1], target = 3
+Output: -1
+Explanation: 3 does not exist in the array, so we return -1.
+
+ +

 

+

Constraints:

+ +
    +
  1. 3 <= mountain_arr.length() <= 10000
  2. +
  3. 0 <= target <= 10^9
  4. +
  5. 0 <= mountain_arr.get(index) <= 10^9
  6. +
diff --git a/problems/shortest-common-supersequence/README.md b/problems/shortest-common-supersequence/README.md index 2b73f982e..75cce416d 100644 --- a/problems/shortest-common-supersequence/README.md +++ b/problems/shortest-common-supersequence/README.md @@ -7,7 +7,7 @@ [< Previous](https://github.com/openset/leetcode/tree/master/problems/shortest-path-in-binary-matrix "Shortest Path in Binary Matrix")                  -Next > +[Next >](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample "Statistics from a Large Sample") ## 1092. Shortest Common Supersequence (Hard) diff --git a/problems/statistics-from-a-large-sample/README.md b/problems/statistics-from-a-large-sample/README.md new file mode 100644 index 000000000..bc2e00877 --- /dev/null +++ b/problems/statistics-from-a-large-sample/README.md @@ -0,0 +1,51 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/shortest-common-supersequence "Shortest Common Supersequence") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/car-pooling "Car Pooling") + +## 1093. Statistics from a Large Sample (Medium) + +

We sampled integers between 0 and 255, and stored the results in an array countcount[k] is the number of integers we sampled equal to k.

+ +

Return the minimum, maximum, mean, median, and mode of the sample respectively, as an array of floating point numbers.  The mode is guaranteed to be unique.

+ +

(Recall that the median of a sample is:

+ + + +

 

+

Example 1:

+
Input: count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
+Output: [1.00000,3.00000,2.37500,2.50000,3.00000]
+

Example 2:

+
Input: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
+Output: [1.00000,4.00000,2.18182,2.00000,1.00000]
+
+

 

+

Constraints:

+ +
    +
  1. count.length == 256
  2. +
  3. 1 <= sum(count) <= 10^9
  4. +
  5. The mode of the sample that count represents is unique.
  6. +
  7. Answers within 10^-5 of the true value will be accepted as correct.
  8. +
+ +### Related Topics + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] + [[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] + +### Hints +
+Hint 1 +The hard part is the median. Write a helper function which finds the k-th element from the sample. +
diff --git a/tag/math/README.md b/tag/math/README.md index 3f1921a0a..53bbed10c 100644 --- a/tag/math/README.md +++ b/tag/math/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 1093 | [大样本统计](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Medium | | 1073 | [负二进制数相加](https://github.com/openset/leetcode/tree/master/problems/adding-two-negabinary-numbers) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | Medium | | 1067 | [范围内的数字计数](https://github.com/openset/leetcode/tree/master/problems/digit-count-in-range) 🔒 | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Hard | | 1058 | [最小化舍入误差以满足目标](https://github.com/openset/leetcode/tree/master/problems/minimize-rounding-error-to-meet-target) 🔒 | [[贪心算法](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)] [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Medium | diff --git a/tag/two-pointers/README.md b/tag/two-pointers/README.md index da2a928dd..b33382886 100644 --- a/tag/two-pointers/README.md +++ b/tag/two-pointers/README.md @@ -9,6 +9,7 @@ | # | 题名 | 标签 | 难度 | | :-: | - | - | :-: | +| 1093 | [大样本统计](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Medium | | 1004 | [最大连续1的个数 III](https://github.com/openset/leetcode/tree/master/problems/max-consecutive-ones-iii) | [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Medium | | 992 | [K 个不同整数的子数组](https://github.com/openset/leetcode/tree/master/problems/subarrays-with-k-different-integers) | [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Hard | | 986 | [区间列表的交集](https://github.com/openset/leetcode/tree/master/problems/interval-list-intersections) | [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Medium |