File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 184
184
387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
185
185
392|[ Is Subsequence] ( ./0392-is-subsequence.js ) |Easy|
186
186
394|[ Decode String] ( ./0394-decode-string.js ) |Medium|
187
+ 395|[ Longest Substring with At Least K Repeating Characters] ( ./0395-longest-substring-with-at-least-k-repeating-characters.js ) |Medium|
187
188
405|[ Convert a Number to Hexadecimal] ( ./0405-convert-a-number-to-hexadecimal.js ) |Easy|
188
189
412|[ Fizz Buzz] ( ./0412-fizz-buzz.js ) |Easy|
189
190
414|[ Third Maximum Number] ( ./0414-third-maximum-number.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 395. Longest Substring with At Least K Repeating Characters
3
+ * https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a string s and an integer k, return the length of the longest substring of s such
7
+ * that the frequency of each character in this substring is greater than or equal to k.
8
+ *
9
+ * If no such substring exists, return 0.
10
+ */
11
+
12
+ /**
13
+ * @param {string } s
14
+ * @param {number } k
15
+ * @return {number }
16
+ */
17
+ var longestSubstring = function ( s , k ) {
18
+ for ( const char of Array . from ( new Set ( s ) ) ) {
19
+ if ( s . match ( new RegExp ( char , 'g' ) ) . length < k ) {
20
+ return Math . max ( ...s . split ( char ) . map ( str => longestSubstring ( str , k ) ) ) ;
21
+ }
22
+ }
23
+ return s . length ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments