题目链接:2043. 简易银行系统
如题,计算即可。
from typing import List
class Bank:
def __init__(self, balance: List[int]):
self.accounts = {i + 1: m for i, m in enumerate(balance)}
def transfer(self, account1: int, account2: int, money: int) -> bool:
if account1 in self.accounts and account2 in self.accounts and self.accounts[account1] >= money:
self.accounts[account1] -= money
self.accounts[account2] += money
return True
return False
def deposit(self, account: int, money: int) -> bool:
if account in self.accounts:
self.accounts[account] += money
return True
return False
def withdraw(self, account: int, money: int) -> bool:
if account in self.accounts and self.accounts[account] >= money:
self.accounts[account] -= money
return True
return False