(int arr[],int n)
| 1 | class Solution{ |
| 2 | //Function to check whether there is a subarray present with 0-sum or not. |
| 3 | static boolean findsum(int arr[],int n) |
| 4 | { |
| 5 | // declare a set data structure |
| 6 | HashSet<Integer> res = new HashSet<>(); |
| 7 | // Variable to calculate sum |
| 8 | int sum=0; |
| 9 | // Traversing the array |
| 10 | for(int i=0;i<n;i++) |
| 11 | { |
| 12 | res.add(sum); |
| 13 | sum+=arr[i]; |
| 14 | if(res.contains(sum)) |
| 15 | { |
| 16 | return true; |
| 17 | } |
| 18 | } |
| 19 | return false; |
| 20 | } |
| 21 | } |