Skip to content

Commit 4e5d0f3

Browse files
committed
Minor changes
1 parent 3397148 commit 4e5d0f3

2 files changed

Lines changed: 71 additions & 75 deletions

File tree

pom.xml

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
<version>1.2</version>
2323
</dependency>
2424

25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter</artifactId>
28+
<version>5.12.2</version>
29+
<scope>test</scope>
30+
</dependency>
31+
32+
<!-- Java Microbenchmark Harness-->
2533
<dependency>
2634
<groupId>org.openjdk.jmh</groupId>
2735
<artifactId>jmh-core</artifactId>
@@ -32,65 +40,61 @@
3240
<artifactId>jmh-generator-annprocess</artifactId>
3341
<version>1.37</version>
3442
</dependency>
43+
<!--Java Microbenchmark Harness-->
3544

36-
<dependency>
37-
<groupId>org.junit.jupiter</groupId>
38-
<artifactId>junit-jupiter</artifactId>
39-
<version>5.12.2</version>
40-
<scope>test</scope>
41-
</dependency>
4245
</dependencies>
4346

44-
45-
<build>
46-
<plugins>
47-
<plugin>
48-
<groupId>org.apache.maven.plugins</groupId>
49-
<artifactId>maven-compiler-plugin</artifactId>
50-
<version>3.13.0</version>
51-
<configuration>
52-
<source>${maven.compiler.source}</source>
53-
<target>${maven.compiler.target}</target>
54-
<annotationProcessorPaths>
55-
<path>
56-
<groupId>org.openjdk.jmh</groupId>
57-
<artifactId>jmh-generator-annprocess</artifactId>
58-
<version>1.37</version>
59-
</path>
60-
</annotationProcessorPaths>
61-
</configuration>
62-
</plugin>
63-
<plugin>
64-
<artifactId>maven-dependency-plugin</artifactId>
65-
<executions>
66-
<execution>
67-
<id>build-classpath</id>
68-
<goals>
69-
<goal>build-classpath</goal>
70-
</goals>
71-
<configuration>
72-
<includeScope>runtime</includeScope>
73-
<outputProperty>depClasspath</outputProperty>
74-
</configuration>
75-
</execution>
76-
</executions>
77-
</plugin>
78-
<plugin>
79-
<groupId>org.codehaus.mojo</groupId>
80-
<artifactId>exec-maven-plugin</artifactId>
81-
<version>3.5.0</version>
82-
<configuration>
83-
<mainClass>Dojo</mainClass>
84-
<systemProperties>
85-
<systemProperty>
86-
<key>java.class.path</key>
87-
<!--suppress MavenModelInspection -->
88-
<value>${project.build.outputDirectory}${path.separator}${depClasspath}</value>
89-
</systemProperty>
90-
</systemProperties>
91-
</configuration>
92-
</plugin>
93-
</plugins>
94-
</build>
47+
<!--Java Microbenchmark Harness-->
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
<version>3.13.0</version>
54+
<configuration>
55+
<source>${maven.compiler.source}</source>
56+
<target>${maven.compiler.target}</target>
57+
<annotationProcessorPaths>
58+
<path>
59+
<groupId>org.openjdk.jmh</groupId>
60+
<artifactId>jmh-generator-annprocess</artifactId>
61+
<version>1.37</version>
62+
</path>
63+
</annotationProcessorPaths>
64+
</configuration>
65+
</plugin>
66+
<plugin>
67+
<artifactId>maven-dependency-plugin</artifactId>
68+
<executions>
69+
<execution>
70+
<id>build-classpath</id>
71+
<goals>
72+
<goal>build-classpath</goal>
73+
</goals>
74+
<configuration>
75+
<includeScope>runtime</includeScope>
76+
<outputProperty>depClasspath</outputProperty>
77+
</configuration>
78+
</execution>
79+
</executions>
80+
</plugin>
81+
<plugin>
82+
<groupId>org.codehaus.mojo</groupId>
83+
<artifactId>exec-maven-plugin</artifactId>
84+
<version>3.5.0</version>
85+
<configuration>
86+
<mainClass>Dojo</mainClass>
87+
<systemProperties>
88+
<systemProperty>
89+
<key>java.class.path</key>
90+
<!--suppress MavenModelInspection -->
91+
<value>${project.build.outputDirectory}${path.separator}${depClasspath}</value>
92+
</systemProperty>
93+
</systemProperties>
94+
</configuration>
95+
</plugin>
96+
</plugins>
97+
</build>
98+
<!--Java Microbenchmark Harness-->
9599

96100
</project>

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,17 @@ public int[] asteroidCollision(int[] asteroids) {
1717
continue;
1818
}
1919

20-
if (Math.signum(stack.peek()) != sign) {
21-
if (Math.signum(stack.peek()) > sign) {
22-
while (!stack.isEmpty() && Math.signum(stack.peek()) > sign) {
23-
int top = stack.peek();
24-
25-
if (Math.abs(top) > Math.abs(num)) break;
26-
27-
if (Math.abs(top) == Math.abs(num)) {
28-
stack.pop();
29-
break;
30-
} else if (Math.abs(top) < Math.abs(num)) {
31-
stack.pop();
32-
33-
if (stack.isEmpty()) stack.push(num);
34-
else if (Math.signum(stack.peek()) <= sign) stack.push(num);
35-
}
20+
if (Math.signum(stack.peek()) > sign) {
21+
while (!stack.isEmpty() && Math.signum(stack.peek()) > sign) {
22+
if (Math.abs(stack.peek()) > Math.abs(num)) break;
23+
if (Math.abs(stack.peek()) == Math.abs(num)) {
24+
stack.pop();
25+
break;
26+
}
27+
if (Math.abs(stack.peek()) < Math.abs(num)) {
28+
stack.pop();
29+
if (stack.isEmpty() || Math.signum(stack.peek()) <= sign) stack.push(num);
3630
}
37-
} else {
38-
stack.push(num);
3931
}
4032
} else {
4133
stack.push(num);

0 commit comments

Comments
 (0)