-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path2043. Simple Bank System.java
More file actions
37 lines (32 loc) · 899 Bytes
/
2043. Simple Bank System.java
File metadata and controls
37 lines (32 loc) · 899 Bytes
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
class Bank {
long[] balance;
public Bank(long[] balance) {
this.balance = balance;
}
public boolean transfer(int account1, int account2, long money) {
if (
account1 > balance.length ||
account2 > balance.length ||
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 > balance.length) {
return false;
}
balance[account - 1] += money;
return true;
}
public boolean withdraw(int account, long money) {
if (account > balance.length || balance[account - 1] < money) {
return false;
}
balance[account - 1] -= money;
return true;
}
}