We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e69dcb5 commit 9c1303dCopy full SHA for 9c1303d
2949-count-beautiful-substrings-ii.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {number} k
4
+ * @return {number}
5
+ */
6
+var beautifulSubstrings = function(s, k) {
7
+ let ans = 0, cur = 0;
8
+ let mp = new Map();
9
+ mp.set(0, [-1]);
10
+ for (let i = 0; i < s.length; i++) {
11
+ let ch = s[i];
12
+ if (ch === 'a' || ch === 'e' || ch === 'i' || ch === 'o' || ch === 'u') {
13
+ cur++;
14
+ } else {
15
+ cur--;
16
+ }
17
+ for (let x of (mp.get(cur) || []) ) {
18
+ let d = (i - x) / 2;
19
+ if (Math.pow(d, 2) % k === 0) {
20
+ ans++;
21
22
23
+ if (!mp.has(cur)) mp.set(cur, []);
24
+ mp.get(cur).push(i);
25
26
+ return ans;
27
+};
0 commit comments