File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,228 LeetCode solutions in JavaScript
1
+ # 1,229 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
997
997
1313|[ Decompress Run-Length Encoded List] ( ./solutions/1313-decompress-run-length-encoded-list.js ) |Easy|
998
998
1314|[ Matrix Block Sum] ( ./solutions/1314-matrix-block-sum.js ) |Medium|
999
999
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|
1000
1001
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|
1001
1002
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|
1002
1003
1319|[ Number of Operations to Make Network Connected] ( ./solutions/1319-number-of-operations-to-make-network-connected.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments