fork download
  1. import java.util.HashSet;
  2. import java.util.Scanner;
  3. public class Main {
  4. public static void main(String[] a) {
  5. try (Scanner in = new Scanner(System.in)) {
  6. while (in.hasNext()) {
  7. String line = in.nextLine().replace("[", "").replace(",", "").replace("]", "");
  8. System.out.println(line + " -> " + parseLine(line));
  9. }
  10. }
  11. }
  12. public static boolean parseLine(String line) {
  13. boolean flag = false;
  14. try (Scanner in = new Scanner(line)) {
  15. HashSet<Integer> set = new HashSet<>();
  16. while (in.hasNext()) {
  17. int x = in.nextInt();
  18. if (x==0 || !set.add((x<0)?(-x):(x))) {
  19. flag = true;
  20. break;
  21. }
  22. }
  23. }
  24. return flag;
  25. }
  26. }
Success #stdin #stdout 0.08s 4386816KB
stdin
[1, 2, 3]
[-5, -3, -1, 2, 4, 6]
[]
[-1, 1]
[-97364, -71561, -69336, 19675, 71561, 97863] 
[-53974, -39140, -36561, -23935, -15680, 0]
stdout
1 2 3 -> false
-5 -3 -1 2 4 6 -> false
 -> false
-1 1 -> true
-97364 -71561 -69336 19675 71561 97863  -> true
-53974 -39140 -36561 -23935 -15680 0 -> true