Skip to content

Commit bbc837f

Browse files
add 3662
1 parent aed611e commit bbc837f

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
| 3908 | [Valid Digit Number](https://leetcode.com/problems/valid-digit-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3908.java) | | Easy |
2020
| 3978 | [Unique Middle Element](https://leetcode.com/problems/unique-middle-element/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3978.java) | | Easy |
2121
| 3701 | [Compute Alternating Sum](https://leetcode.com/problems/compute-alternating-sum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3701.java) | | Easy |
22+
| 3662 | [Filter Characters by Frequency](https://leetcode.com/problems/filter-characters-by-frequency/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3662.java) | | Easy |
2223
| 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy |
2324
| 3491 | [Phone Number Prefix](https://leetcode.com/problems/phone-number-prefix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java) | | Easy |
2425
| 3477 | [Fruits Into Baskets II](https://leetcode.com/problems/fruits-into-baskets-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java) | | Easy |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3662 {
4+
public static class Solution1 {
5+
public String filterCharacters(String s, int k) {
6+
int[] freq = new int[26];
7+
for (int i = 0; i < s.length(); i++) {
8+
freq[s.charAt(i) - 'a']++;
9+
}
10+
StringBuilder sb = new StringBuilder();
11+
for (int i = 0; i < s.length(); i++) {
12+
if (freq[s.charAt(i) - 'a'] < k) {
13+
sb.append(s.charAt(i));
14+
}
15+
}
16+
return sb.toString();
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)