Skip to content

Commit 6a94019

Browse files
committed
Add solution #1316
1 parent 1a5ab1a commit 6a94019

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,228 LeetCode solutions in JavaScript
1+
# 1,229 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -997,6 +997,7 @@
997997
1313|[Decompress Run-Length Encoded List](./solutions/1313-decompress-run-length-encoded-list.js)|Easy|
998998
1314|[Matrix Block Sum](./solutions/1314-matrix-block-sum.js)|Medium|
999999
1315|[Sum of Nodes with Even-Valued Grandparent](./solutions/1315-sum-of-nodes-with-even-valued-grandparent.js)|Medium|
1000+
1316|[Distinct Echo Substrings](./solutions/1316-distinct-echo-substrings.js)|Hard|
10001001
1317|[Convert Integer to the Sum of Two No-Zero Integers](./solutions/1317-convert-integer-to-the-sum-of-two-no-zero-integers.js)|Easy|
10011002
1318|[Minimum Flips to Make a OR b Equal to c](./solutions/1318-minimum-flips-to-make-a-or-b-equal-to-c.js)|Medium|
10021003
1319|[Number of Operations to Make Network Connected](./solutions/1319-number-of-operations-to-make-network-connected.js)|Medium|
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* 1316. Distinct Echo Substrings
3+
* https://leetcode.com/problems/distinct-echo-substrings/
4+
* Difficulty: Hard
5+
*
6+
* Return the number of distinct non-empty substrings of text that can be written as the
7+
* concatenation of some string with itself (i.e. it can be written as a + a where a is
8+
* some string).
9+
*/
10+
11+
/**
12+
* @param {string} text
13+
* @return {number}
14+
*/
15+
var distinctEchoSubstrings = function(text) {
16+
const set = new Set();
17+
18+
for (let size = 1; size <= text.length / 2; size++) {
19+
let count = 0;
20+
21+
for (let left = 0, right = size; right < text.length; left++, right++) {
22+
if (text[left] === text[right]) {
23+
count++;
24+
} else {
25+
count = 0;
26+
}
27+
28+
if (count === size) {
29+
set.add(text.slice(left - size + 1, right + 1));
30+
count--;
31+
}
32+
}
33+
}
34+
35+
return set.size;
36+
};

0 commit comments

Comments
 (0)