- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJavaSubArray.java
More file actions
Latest commit
21 lines (18 loc) · 637 Bytes
/
Copy pathJavaSubArray.java
File metadata and controls
21 lines (18 loc) · 637 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// https://www.hackerrank.com/challenges/java-negative-subarray/problem
importhelper.InputHelper;
publicclassJavaSubArray {
publicstaticvoidmain(String[] args) {
int[] array = InputHelper.get1DArray(InputHelper.takeLength());
System.out.println(negativeSumSubArrays(array));
}
privatestaticintnegativeSumSubArrays(int[] array) {
intcount = 0;
for (inti = 0 ; i < array.length ; i++) {
for (intj = i, sum = 0 ; j < array.length ; j++) {
sum += array[j];
count += sum < 0 ? 1 : 0 ;
}
}
returncount;
}
}