

문제의 설명 그대로 간단하게 구현만 하면 되는 문제였다.
어렵지는 않았으나, 효율적인 풀이가 무엇인지 조금 고민이 되었다.
각 연산의 시간복잡도는 이고 공간복잡도는 이다.
class Bank:
def __init__(self, balance: List[int]):
self.balance = balance
def valid(self, i):
return 1 <= i <= len(self.balance)
def transfer(self, account1: int, account2: int, money: int) -> bool:
if not self.valid(account1) or not self.valid(account2):
return False
if self.balance[account1 - 1] < money:
return False
self.balance[account1 - 1] -= money
self.balance[account2 - 1] += money
return True
def deposit(self, account: int, money: int) -> bool:
if not self.valid(account):
return False
self.balance[account-1] += money
return True
def withdraw(self, account: int, money: int) -> bool:
if not self.valid(account) or self.balance[account - 1] < money:
return False
self.balance[account-1] -= money
return True
# Your Bank object will be instantiated and called as such:
# obj = Bank(balance)
# param_1 = obj.transfer(account1,account2,money)
# param_2 = obj.deposit(account,money)
# param_3 = obj.withdraw(account,money)

다른 풀이법도 나와 별 다를 것이 없었다.
미세하게 코드가 다른 것을 빼면 똑같았는데, 간단한 문제였기 때문인 것 같다.
쉬운 문제들은 좋다.