Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 405f6ac

Browse files
committed
Add solution #395
1 parent 8c67128 commit 405f6ac

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
387|[First Unique Character in a String](./0387-first-unique-character-in-a-string.js)|Easy|
185185
392|[Is Subsequence](./0392-is-subsequence.js)|Easy|
186186
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|
187188
405|[Convert a Number to Hexadecimal](./0405-convert-a-number-to-hexadecimal.js)|Easy|
188189
412|[Fizz Buzz](./0412-fizz-buzz.js)|Easy|
189190
414|[Third Maximum Number](./0414-third-maximum-number.js)|Easy|

0 commit comments

Comments
 (0)