-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
45 lines (36 loc) · 1.16 KB
/
Solution.java
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
import java.util.ArrayList;
import java.util.Arrays;
class Bank {
private long[] moneyList;
private int n;
public Bank(long[] balance) {
this.moneyList = balance;
this.n = balance.length;
}
public boolean transfer(int account1, int account2, long money) {
if (account1 > n || account2 > n || this.moneyList[account1 - 1] < money)
return false;
this.moneyList[account1 - 1] -= money;
this.moneyList[account2 - 1] += money;
return true;
}
public boolean deposit(int account, long money) {
if (account > n)
return false;
this.moneyList[account - 1] += money;
return true;
}
public boolean withdraw(int account, long money) {
if (account > n || this.moneyList[account - 1] < money)
return false;
this.moneyList[account - 1] -= money;
return true;
}
}
/**
* Your Bank object will be instantiated and called as such:
* Bank obj = new Bank(balance);
* boolean param_1 = obj.transfer(account1,account2,money);
* boolean param_2 = obj.deposit(account,money);
* boolean param_3 = obj.withdraw(account,money);
*/