File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 374
374
463|[ Island Perimeter] ( ./0463-island-perimeter.js ) |Medium|
375
375
464|[ Can I Win] ( ./0464-can-i-win.js ) |Medium|
376
376
466|[ Count The Repetitions] ( ./0466-count-the-repetitions.js ) |Hard|
377
+ 467|[ Unique Substrings in Wraparound String] ( ./0467-unique-substrings-in-wraparound-string.js ) |Medium|
377
378
472|[ Concatenated Words] ( ./0472-concatenated-words.js ) |Hard|
378
379
476|[ Number Complement] ( ./0476-number-complement.js ) |Easy|
379
380
482|[ License Key Formatting] ( ./0482-license-key-formatting.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 467. Unique Substrings in Wraparound String
3
+ * https://leetcode.com/problems/unique-substrings-in-wraparound-string/
4
+ * Difficulty: Medium
5
+ *
6
+ * We define the string base to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz",
7
+ * so base will look like this:
8
+ * - "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".
9
+ *
10
+ * Given a string s, return the number of unique non-empty substrings of s are present in base.
11
+ */
12
+
13
+ /**
14
+ * @param {string } s
15
+ * @return {number }
16
+ */
17
+ var findSubstringInWraproundString = function ( s ) {
18
+ const maxLength = new Array ( 26 ) . fill ( 0 ) ;
19
+ let count = 0 ;
20
+
21
+ for ( let i = 0 ; i < s . length ; i ++ ) {
22
+ count = i > 0 && ( s . charCodeAt ( i ) - s . charCodeAt ( i - 1 ) - 1 ) % 26 === 0 ? count + 1 : 1 ;
23
+ const index = s . charCodeAt ( i ) - 97 ;
24
+ maxLength [ index ] = Math . max ( maxLength [ index ] , count ) ;
25
+ }
26
+
27
+ return maxLength . reduce ( ( sum , n ) => sum + n , 0 ) ;
28
+ } ;
You can’t perform that action at this time.
0 commit comments