Skip to content

Commit 124905b

Browse files
committed
Time: 20 ms (90.98%), Space: 47.6 MB (82.51%) - LeetHub
1 parent b41fbfe commit 124905b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from typing import List
2+
3+
4+
class Bank:
5+
6+
def __init__(self, balance: List[int]):
7+
self.balance = balance
8+
self.n = len(balance)
9+
10+
def transfer(self, account1: int, account2: int, money: int) -> bool:
11+
if account1 - 1 > self.n or account2 - 1 > self.n:
12+
return False
13+
if self.balance[account1 - 1] < money:
14+
return False
15+
self.balance[account1 - 1] -= money
16+
self.balance[account2 - 1] += money
17+
return True
18+
19+
def deposit(self, account: int, money: int) -> bool:
20+
if account - 1 > self.n:
21+
return False
22+
self.balance[account - 1] += money
23+
return True
24+
25+
def withdraw(self, account: int, money: int) -> bool:
26+
if account - 1 > self.n:
27+
return False
28+
if self.balance[account - 1] < money:
29+
return False
30+
self.balance[account - 1] -= money
31+
return True
32+
33+
34+
bank = Bank([10, 100, 20, 50, 30])
35+
print(bank.withdraw(3, 10))
36+
print(bank.transfer(5, 1, 20))
37+
print(bank.deposit(5, 20))
38+
print(bank.transfer(3, 4, 15))
39+
print(bank.withdraw(10, 50))

0 commit comments

Comments
 (0)