-
Notifications
You must be signed in to change notification settings - Fork 31
/
2043.java
43 lines (38 loc) · 1.33 KB
/
2043.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
class Bank {
private long[] Balance;
public Bank(long[] balance) {
Balance = new long[balance.length];
for(int i=0;i<Balance.length;i++){
Balance[i] = balance[i];
}
}
public boolean transfer(int account1, int account2, long money) {
if(account1-1 >= 0 && account2-1 >= 0 && account1-1 < Balance.length && account2-1 < Balance.length && Balance[account1-1] >= money){
Balance[account1-1] -= money;
Balance[account2-1] += money;
return true;
}
return false;
}
public boolean deposit(int account, long money) {
if(account-1 >= 0 && account-1 < Balance.length){
Balance[account-1] += money;
return true;
}
return false;
}
public boolean withdraw(int account, long money) {
if(account-1 >= 0 && account-1 < Balance.length && Balance[account-1] >= money){
Balance[account-1] -= money;
return true;
}
return false;
}
}
/**
* 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);
*/