Skip to content

Commit 0bb02d1

Browse files
add 2043
1 parent 4867456 commit 0bb02d1

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2043|[Simple Bank System](https://leetcode.com/problems/simple-bank-system/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2043.java) ||Medium||
1112
|2042|[Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2042.java) ||Easy||
1213
|2039|[The Time When the Network Becomes Idle](https://leetcode.com/problems/the-time-when-the-network-becomes-idle/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2039.java) ||Medium||
1314
|2038|[Remove Colored Pieces if Both Neighbors are the Same Color](https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2038.java) ||Medium||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2043 {
7+
public static class Solution1 {
8+
class Bank {
9+
10+
List<Long> list;
11+
12+
public Bank(long[] balance) {
13+
list = new ArrayList<>();
14+
for (long b : balance) {
15+
list.add(b);
16+
}
17+
}
18+
19+
public boolean transfer(int account1, int account2, long money) {
20+
if (account1 - 1 >= list.size()) {
21+
return false;
22+
} else if (list.get(account1 - 1) < money) {
23+
return false;
24+
} else if (account2 - 1 >= list.size()) {
25+
return false;
26+
} else {
27+
Long original = list.remove(account1 - 1);
28+
list.add(account1 - 1, original - money);
29+
Long remove = list.remove(account2 - 1);
30+
list.add(account2 - 1, remove + money);
31+
return true;
32+
}
33+
}
34+
35+
public boolean deposit(int account, long money) {
36+
if (account - 1 >= list.size()) {
37+
return false;
38+
} else {
39+
Long original = list.remove(account - 1);
40+
list.add(account - 1, original + money);
41+
return true;
42+
}
43+
}
44+
45+
public boolean withdraw(int account, long money) {
46+
if (account - 1 >= list.size()) {
47+
return false;
48+
} else if (list.get(account - 1) < money) {
49+
return false;
50+
} else {
51+
Long original = list.remove(account - 1);
52+
list.add(account - 1, original - money);
53+
return true;
54+
}
55+
}
56+
}
57+
58+
}
59+
}

0 commit comments

Comments
 (0)