Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0949a20

Browse files
Add solution to 523.
1 parent f22133f commit 0949a20

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} k
4+
* @return {boolean}
5+
*/
6+
var checkSubarraySum = function (nums, k) {
7+
const map = {
8+
0: 0,
9+
};
10+
let s = 0;
11+
12+
for (let i = 0; i < nums.length; i++) {
13+
s += nums[i];
14+
const r = s % k;
15+
16+
if (map[r] === undefined) {
17+
map[r] = i + 1;
18+
} else if (map[r] < i) {
19+
return true;
20+
}
21+
}
22+
23+
return false;
24+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /