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 84cd947 commit ccc1b6aCopy full SHA for ccc1b6a
lcp/LCP 18. 早餐组合/Solution.swift
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ func breakfastNumber(_ staple: [Int], _ drinks: [Int], _ x: Int) -> Int {
3
+ let mod = 1000000007
4
+ var result = 0
5
+ let sortedDrinks = drinks.sorted()
6
+
7
+ for s in staple {
8
+ let remaining = x - s
9
+ if remaining >= sortedDrinks.first ?? 0 {
10
+ var left = 0
11
+ var right = sortedDrinks.count - 1
12
13
+ while left < right {
14
+ let mid = (left + right + 1) / 2
15
+ if sortedDrinks[mid] <= remaining {
16
+ left = mid
17
+ } else {
18
+ right = mid - 1
19
+ }
20
21
+ result = (result + left + 1) % mod
22
23
24
+ return result
25
26
+}
0 commit comments