8000 feat: add question #lcp18 · hi-dhl/Leetcode-Solution-CPP-C@e4882d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4882d2

Browse files
committed
feat: add question #lcp18
1 parent 398bf62 commit e4882d2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

code/_lcp18/Solution.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
0