Untitled
unknown
plain_text
14 days ago
1.3 kB
3
Indexable
from typing import List, Dict
def solution(queries: List[List[str]]) -> List[str]:
balances: Dict[str, int] = {}
ans = []
for query in queries:
op = query[0]
if op == "CREATE_ACCOUNT":
_, timestamp, account_id = query
if account_id in balances:
ans.append("false")
else:
balances[account_id] = 0
ans.append("true")
elif op == "DEPOSIT":
_, timestamp, account_id, amount_str = query
amount = int(amount_str)
if account_id not in balances:
ans.append("")
else:
balances[account_id] += amount
ans.append(str(balances[account_id]))
elif op == "TRANSFER":
_, timestamp, source, target, amount_str = query
amount = int(amount_str)
if source not in balances:
ans.append("")
elif target not in balances:
ans.append("")
elif source == target:
ans.append("")
elif balances[source] < amount:
ans.append("")
else:
balances[source] -= amount
balances[target] += amount
ans.append(str(balances[source]))
return ansEditor is loading...
Leave a Comment