-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSimpleBankSystem.java
38 lines (33 loc) · 1.1 KB
/
SimpleBankSystem.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
/*https://leetcode.com/problems/simple-bank-system/*/
class Bank {
long[] balance;
public Bank(long[] balance) {
this.balance = balance;
}
public boolean transfer(int account1, int account2, long money) {
int a1 = account1-1, a2 = account2-1;
if (a1 >= balance.length || a2 >= balance.length || balance[a1] < money) return false;
balance[a1] -= money;
balance[a2] += money;
return true;
}
public boolean deposit(int account, long money) {
int a = account-1;
if (a >= balance.length) return false;
balance[a] += money;
return true;
}
public boolean withdraw(int account, long money) {
int a = account-1;
if (a >= balance.length || balance[a] < money) return false;
balance[a] -= 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);
*/