-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem2043.py
45 lines (35 loc) · 1.31 KB
/
problem2043.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# <---coding: utf-8--->
# @Time: 2022/3/18/21:36
# @Author = posiondy
# @Email: 1547590574@qq.com
# @Software: PyCharm
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 account1 < 1 or account1 > len(self.balance) or account2 < 1 or account2 > len(self.balance):
return False
if self.balance[account1 - 1] < money:
return False
else:
self.balance[account1 - 1] -= money
self.balance[account2 -1] += money
return True
def deposit(self, account: int, money: int) -> bool:
if account < 1 or account > len(self.balance) :
return False
else:
self.balance[account - 1] += money
return True
def withdraw(self, account: int, money: int) -> bool:
if account < 1 or account > len(self.balance) or self.balance[account - 1] < money:
return False
else:
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)