-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckSubarraySum.java
More file actions
35 lines (32 loc) · 1001 Bytes
/
checkSubarraySum.java
File metadata and controls
35 lines (32 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Author : WindAsMe
* File : checkSubarraySum.java
* Time : Create on 18-8-7
* Location : ../Home/JavaForLeeCode2/checkSubarraySum.java
* Function : LeetCode No.523
*/
public class checkSubarraySum {
private static boolean checkSubarraySumResult(int[] nums, int k) {
// k == 0 must be concerned !!
if (k == 0) {
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] == 0 && nums[i + 1] == 0)
return true;
}
return false;
}
for (int i = 0; i < nums.length - 1; i++) {
int sum = nums[i];
for (int i1 = i + 1; i1 < nums.length; i1++) {
sum += nums[i1];
if (sum % k == 0)
return true;
}
}
return false;
}
public static void main(String[] args) {
int[] nums = {23,2,6,4,7};
System.out.println(checkSubarraySumResult(nums, 0));
}
}