8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 398bf62 commit e4882d2Copy full SHA for e4882d2
code/_lcp18/Solution.cpp
@@ -0,0 +1,29 @@
1
+//
2
+// Created by DHL on 2022/7/30.
3
4
+
5
+class Solution {
6
+public:
7
+ int breakfastNumber(vector<int> &staple, vector<int> &drinks, int x) {
8
+ int *arr = new int[x + 1]();
9
+ int slen = staple.size();
10
+ for (int i = 0; i < slen; i++) {
11
+ if (staple[i] > x) continue;
12
+ arr[staple[i]]++;
13
+ }
14
15
+ for (int i = 1; i <= x; i++) {
16
+ arr[i] += arr[i - 1];
17
18
19
+ int dlen = drinks.size();
20
+ int ans = 0;
21
+ for (int i = 0; i < dlen; i++) {
22
+ if (drinks[i] > x) continue;
23
+ ans += arr[x - drinks[i]];
24
+ ans = ans % 1000000007;
25
26
+ delete[] arr;
27
+ return ans;
28
29
+};
0 commit comments