-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2043-Simple-Bank-System.py
More file actions
28 lines (26 loc) · 959 Bytes
/
2043-Simple-Bank-System.py
File metadata and controls
28 lines (26 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Bank:
def __init__(self, balance: List[int]):
self.dic = {}
self.n = len(balance)
for i in range(self.n):
self.dic[i+1] = balance[i]
def transfer(self, account1: int, account2: int, money: int) -> bool:
if account1 < 1 or account1 > self.n or account2 < 1 or account2 > self.n:
return False
if self.dic[account1] >= money:
self.dic[account1] -= money
self.dic[account2] += money
return True
return False
def deposit(self, account: int, money: int) -> bool:
if account < 1 or account > self.n:
return False
self.dic[account] += money
return True
def withdraw(self, account: int, money: int) -> bool:
if account < 1 or account > self.n:
return False
if self.dic[account] >= money:
self.dic[account] -= money
return True
return False