forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
42 lines (37 loc) · 1.11 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
class Bank {
private long[] balance;
private int n;
public Bank(long[] balance) {
this.balance = balance;
this.n = balance.length;
}
public boolean transfer(int account1, int account2, long money) {
if (account1 > n || account2 > n || balance[account1 - 1] < money) {
return false;
}
balance[account1 - 1] -= money;
balance[account2 - 1] += money;
return true;
}
public boolean deposit(int account, long money) {
if (account > n) {
return false;
}
balance[account - 1] += money;
return true;
}
public boolean withdraw(int account, long money) {
if (account > n || balance[account - 1] < money) {
return false;
}
balance[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);
*/