public int rearrangeCharacters(String s, String target) {
int[] cnt1 = new int[26];
int[] cnt2 = new int[26];
for (int i = 0; i < s.length(); ++i) {
++cnt1[s.charAt(i) - 'a'];
}
for (int i = 0; i < target.length(); ++i) {
++cnt2[target.charAt(i) - 'a'];
}
int ans = 100;
for (int i = 0; i < 26; ++i) {
if (cnt2[i] > 0) {
ans = Math.min(ans, cnt1[i] / cnt2[i]);
}
}
return ans;
}
2023.1.13-----leetcode.2287
最新推荐文章于 2024-08-22 21:24:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)