8000 * Done with "2043. Simple Bank System". · garciparedes/leetcode@b6fe380 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6fe380

Browse files
committed
* Done with "2043. Simple Bank System".
1 parent f1e5083 commit b6fe380

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

problems/2043_simple_bank_system.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Bank:
2+
3+
def __init__(self, balance: List[int]):
4+
self.balance = balance
5+
6+
def transfer(self, account1: int, account2: int, money: int) -> bool:
7+
if not self.withdraw(account1, money):
8+
return False
9+
if not self.deposit(account2, money):
10+
self.deposit(account1, money)
11+
return False
12+
return True
13+
14+
def deposit(self, account: int, money: int) -> bool:
15+
if account > len(self.balance):
16+
return False
17+
self.balance[account - 1] += money
18+
return True
19+
20+
def withdraw(self, account: int, money: int) -> bool:
21+
if account > len(self.balance):
22+
return False
23+
if self.balance[account - 1] < money:
24+
return False
25+
self.balance[account - 1] -= money
26+
return True
27+
28+
29+
# Your Bank object will be instantiated and called as such:
30+
# obj = Bank(balance)
31+
# param_1 = obj.transfer(account1,account2,money)
32+
# param_2 = obj.deposit(account,money)
33+
# param_3 = obj.withdraw(account,money)

0 commit comments

Comments
 (0)
0