forked from kamyu104/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-bank-system.py
46 lines (41 loc) · 1.15 KB
/
simple-bank-system.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
46
# Time: ctor: O(1)
# transer: O(1)
# deposit: O(1)
# withdraw: O(1)
# Space: O(1)
class Bank(object):
def __init__(self, balance):
"""
:type balance: List[int]
"""
self.__balance = balance
def transfer(self, account1, account2, money):
"""
:type account1: int
:type account2: int
:type money: int
:rtype: bool
"""
if 1 <= account2 <= len(self.__balance) and self.withdraw(account1, money):
return self.deposit(account2, money)
return False
def deposit(self, account, money):
"""
:type account: int
:type money: int
:rtype: bool
"""
if 1 <= account <= len(self.__balance):
self.__balance[account-1] += money
return True
return False
def withdraw(self, account, money):
"""
:type account: int
:type money: int
:rtype: bool
"""
if 1 <= account <= len(self.__balance) and self.__balance[account-1] >= money:
self.__balance[account-1] -= money
return True
return False