📌  相关文章
📜  意外需求hackerrank解决方案 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:58.030000             🧑  作者: Mango

代码示例1
def filledOrders(order, k):
  total = 0
  for i, v in enumerate(sorted(order)):
    if total + v <= k:
      total += v       # total stays <= k
    else:
      return i         # provides the count
  else:
    return len(order)  # was able to place all orders

print(filledOrders([3, 2, 1], 3))  # Out: 2
print(filledOrders([3, 2, 1], 1))  # Out: 1
print(filledOrders([3, 2, 1], 10)) # Out: 3
print(filledOrders([3, 2, 1], 0))  # Out: 0