fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] arr = {-1,2,-3,3};
  13. System.out.println(findMax(arr));
  14. }
  15.  
  16. static int findMax(int[] nums){
  17. int n = nums.length;
  18.  
  19. int max = Integer.MIN_VALUE;
  20. for(int i = 0;i<n;i++){
  21. for(int j=i;j<n;j++){
  22.  
  23. if(i!= j && (nums[i] == -nums[j] || -nums[i] == nums[j])){
  24. max = Math.max(max,(Math.abs(nums[i])));
  25. }
  26. }
  27. }
  28. if(max == Integer.MIN_VALUE){
  29. return -1;
  30. }
  31.  
  32. return max;
  33. }
  34. }
Success #stdin #stdout 0.08s 52604KB
stdin
Standard input is empty
stdout
3