注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
'''
Your task is to implement an inventory tracking system for a robot retail store.
You are given a transaction log log, where each log item corresponds to one of three transaction types: supply, sell, and upgrade. Log items are provided in the following format:
["supple", "<robot name>", "<count>", "<price>"] - the store reveices <count> units of <robot name>, and each robot costs <price>
["sell", "<robot name>", "<count>"] - the store sells <count> units of <robot name>. If the specified robot is available at different prices, the cheapest ones should be sold first. It is guatanteed that the store will always have enough robots to satisfy all sell transactions.
["upgrade," "<robot name>," "<count>," "<old price>," "<new price>"] - the store upgrades <count> units of <robot name> to a new version that should be sold with a higher price. It is guaranteed that there are <count> units of the older versions that were being sold at a price <old price>
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not words that O(logs.length^2) will fit within the execution time limit.
'''
from collections import deque
def solution(logs):
result = []
robot1 = ""
robot2 = ""
robot1dq = deque()
robot2dq = deque()
for log in logs:
option = log[0]
robotNa","999"]]
Expected return value
[]
logs:
[["supply","v","502","229"],
["sell","v","303"],
["upgrade","v","60","229","252"],
["upgrade","v","108","229","252"],
["sell","v","2"],
["sell","v","72"],
["sell","v","14"],
["supply","W2WmQzC","1099","128"],
["upgrade","W2WmQzC","143","128","141"],
["supply","W2WmQzC","570","465"]]
Expected return value
[69387, 458, 17477, 3528]
''' |