package leetcode;

/**
 * https://leetcode.com/problems/asteroid-collision/
 */
public class Problem735 {
    public int[] asteroidCollision(int[] asteroids) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem735 prob = new Problem735();
        System.out.println(prob.asteroidCollision(new int[]{5, 10, -5})); // [5, 10]
        System.out.println(prob.asteroidCollision(new int[]{8, -8})); // []
        System.out.println(prob.asteroidCollision(new int[]{10, 2, -5})); // [8]
        System.out.println(prob.asteroidCollision(new int[]{-2, -1, 1, 2})); // [-2, -1, 1, 2]
    }
}

@@ -12,16 +12,66 @@
 tcode;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Stack;%0A%0A
 /**%0A * h
@@ -215,35 +215,729 @@
     
-// TODO%0A        return null
+Stack%3CInteger%3E stack = new Stack%3C%3E();%0A        for (int i = 0; i %3C asteroids.length; i++) %7B%0A            if (stack.isEmpty()) %7B%0A                stack.push(asteroids%5Bi%5D);%0A            %7D else %7B%0A                int a = stack.pop();%0A                if (a %3E 0 && asteroids%5Bi%5D %3C 0) %7B%0A                    int sum = a + asteroids%5Bi%5D;%0A                    if (sum %3C 0) %7B%0A                        stack.push(asteroids%5Bi%5D);%0A                    %7D else if (sum %3E 0) %7B%0A                        stack.push(a);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        int%5B%5D result = new int%5Bstack.size()%5D;%0A        for (int i = stack.size() - 1; i %3E= 0; i--) %7B%0A            result%5Bi%5D = stack.pop();%0A        %7D%0A        return result
 ;%0A  
@@ -1049,32 +1049,48 @@
 tem.out.println(
+Arrays.toString(
 prob.asteroidCol
@@ -1114,24 +1114,25 @@
 5, 10, -5%7D))
+)
 ; // %5B5, 10%5D
@@ -1151,32 +1151,48 @@
 tem.out.println(
+Arrays.toString(
 prob.asteroidCol
@@ -1216,16 +1216,17 @@
 8, -8%7D))
+)
 ; // %5B%5D%0A
@@ -1244,32 +1244,48 @@
 tem.out.println(
+Arrays.toString(
 prob.asteroidCol
@@ -1317,15 +1317,17 @@
 5%7D))
+)
 ; // %5B
-8
+10
 %5D%0A  
@@ -1351,16 +1351,32 @@
 println(
+Arrays.toString(
 prob.ast
@@ -1415,16 +1415,17 @@
  1, 2%7D))
+)
 ; // %5B-2

Update problem 735