Skip to content

Commit 98dacc0

Browse files
committed
Add some changes
1 parent ba4c2c6 commit 98dacc0

4 files changed

Lines changed: 85 additions & 2 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Verify.xml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Computer Science problems in Java.
22

33
### Migration status - dojo.net
44
1. ArrayProblems.cs + ArrayProblemsTests.cs [WIP]
5+
2. Add Checker Framework - Clashes with Java Microbenchmark Harness annotation processor
56

67
## Backlog
78
### Problems

src/main/java/org/dojo/leetcode/Stacks.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public int[] asteroidCollision(int[] asteroids) {
1717

1818
if (Math.signum(stack.peek()) != sign) {
1919
if (Math.signum(stack.peek()) > sign) {
20-
while (Math.signum(stack.peek()) > sign) {
20+
while (!stack.isEmpty() && Math.signum(stack.peek()) > sign) {
2121
int top = stack.peek();
2222

2323
if (Math.abs(top) > Math.abs(num)) break;
@@ -42,4 +42,54 @@ public int[] asteroidCollision(int[] asteroids) {
4242

4343
return stack.reversed().stream().mapToInt(i -> i).toArray();
4444
}
45+
46+
// public boolean isValid(String s) {
47+
// Deque<Bracket> stack = new ArrayDeque<>();
48+
// for (int i = 0; i < s.length(); i++) {
49+
// char c = s.charAt(i);
50+
// Bracket bracket = Bracket.fromSymbol(c);
51+
//
52+
// if (stack.isEmpty()) {stack.push(bracket)}
53+
//
54+
// ;
55+
// }
56+
//
57+
// return false;
58+
// }
59+
60+
enum Bracket {
61+
PARENTHESES('(', ')'),
62+
BRACES('{', '}'),
63+
BRACKETS('[', ']');
64+
65+
Bracket(char openSymbol, char closeSymbol) {
66+
this.openSymbol = openSymbol;
67+
this.closeSymbol = closeSymbol;
68+
}
69+
private final char openSymbol;
70+
public char getOpenSymbol() { return openSymbol; }
71+
72+
private final char closeSymbol;
73+
public char getCloseSymbol() { return closeSymbol; }
74+
75+
enum State {
76+
OPEN,
77+
CLOSED
78+
}
79+
80+
public char getSymbol(State state) { return state == State.OPEN ? openSymbol : closeSymbol; }
81+
82+
public static Bracket fromSymbol(char symbol) {
83+
for (Bracket bracket : Bracket.values()) {
84+
if (bracket.getOpenSymbol() == symbol || bracket.getCloseSymbol() == symbol) {
85+
return bracket;
86+
}
87+
}
88+
throw new IllegalArgumentException("Unknown symbol: " + symbol);
89+
}
90+
91+
public static boolean isMatching(char openSymbol, char closeSymbol) {
92+
return fromSymbol(openSymbol).getCloseSymbol() == closeSymbol;
93+
}
94+
}
4595
}

0 commit comments

Comments
 (0)