Skip to content

Commit 3927ec0

Browse files
add 2287
1 parent 138d00d commit 3927ec0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ _If you like this project, please leave me a star._ ★
99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------|-------------
1111
| 2288 |[Apply Discount to Prices](https://leetcode.com/problems/apply-discount-to-prices/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2288.java) || Medium ||
12+
| 2287 |[Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2288.java) || Eaa ||
1213
| 2284 |[Sender With Largest Word Count](https://leetcode.com/problems/sender-with-largest-word-count/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2284.java) || Medium ||
1314
| 2283 |[Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2283.java) || Easy ||
1415
| 2279 |[Maximum Bags With Full Capacity of Rocks](https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2279.java) || Medium ||
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _2287 {
7+
public static class Solution1 {
8+
public int rearrangeCharacters(String s, String target) {
9+
Map<Character, Integer> targetMap = new HashMap<>();
10+
for (char c : target.toCharArray()) {
11+
targetMap.put(c, targetMap.getOrDefault(c, 0) + 1);
12+
}
13+
Map<Character, Integer> sMap = new HashMap<>();
14+
for (char c : s.toCharArray()) {
15+
sMap.put(c, sMap.getOrDefault(c, 0) + 1);
16+
}
17+
int result = Integer.MAX_VALUE;
18+
for (char c : targetMap.keySet()) {
19+
int targetCount = targetMap.get(c);
20+
result = Math.min(result, sMap.getOrDefault(c, 0) / targetCount);
21+
}
22+
return result;
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)