File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Time: ctor: O(1)
2
+ // transer: O(1)
3
+ // deposit: O(1)
4
+ // withdraw: O(1)
5
+ // Space: O(1)
6
+
7
+ class Bank {
8
+ public:
9
+ Bank (vector<long long >& balance) : balance_(balance) {
10
+
11
+ }
12
+
13
+ bool transfer (int account1, int account2, long long money) {
14
+ if (1 <= account2 && account2 <= size (balance_) && withdraw (account1, money)) {
15
+ return deposit (account2, money);
16
+ }
17
+ return false ;
18
+ }
19
+
20
+ bool deposit (int account, long long money) {
21
+ if (1 <= account && account <= size (balance_)) {
22
+ balance_[account - 1 ] += money;
23
+ return true ;
24
+ }
25
+ return false ;
26
+ }
27
+
28
+ bool withdraw (int account, long long money) {
29
+ if (1 <= account && account <= size (balance_) && balance_[account - 1 ] >= money) {
30
+ balance_[account - 1 ] -= money;
31
+ return true ;
32
+ }
33
+ return false ;
34
+ }
35
+
36
+ private:
37
+ vector<long long >& balance_;
38
+ };
You can’t perform that action at this time.
0 commit comments