fork download
  1.  
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. int[] arr = new int[]{15, -2, 2, -8, 1, 7, 10, 23};
  6. int n = arr.length;
  7. int maxLength = 0;
  8. for(int i = 0;i<n;i++){
  9. int currentSum = 0;
  10. for(int j = i ;j<n;j++){
  11. currentSum+=arr[j];
  12.  
  13. if(currentSum==0){
  14. maxLength = Math.max(maxLength,j-i+1);
  15. }
  16. }
  17. }
  18. System.out.println(maxLength);
  19. }
  20. }
  21.  
Success #stdin #stdout 0.08s 52536KB
stdin
Standard input is empty
stdout
5