-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay20
More file actions
29 lines (22 loc) · 932 Bytes
/
Day20
File metadata and controls
29 lines (22 loc) · 932 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
#2043.simple-bank-
from typing import List
class Bank:
def __init__(self, balance: List[int]):
self.balance = balance
def transfer(self, account1: int, account2: int, money: int) -> bool:
if 1 <= account1 <= len(self.balance) and 1 <= account2 <= len(self.balance):
if self.balance[account1 - 1] >= money:
self.balance[account1 - 1] -= money
self.balance[account2 - 1] += money
return True
return False
def deposit(self, account: int, money: int) -> bool:
if 1 <= account <= len(self.balance):
self.balance[account - 1] += money
return True
return False
def withdraw(self, account: int, money: int) -> bool:
if 1 <= account <= len(self.balance) and self.balance[account - 1] >= money:
self.balance[account - 1] -= money
return True
return False