Skip to content

Commit e813142

Browse files
Create 1189_Maximum_Number_of_Balloons.java (qiyuangong#52)
* Create 1189_Maximum_Number_of_Balloons.java * Create 1374_Generate_a_String_With_Characters_That_Have_Odd_Counts_Solution.py Contributed by @ChesterChangLiu
1 parent 76137fa commit e813142

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int maxNumberOfBalloons(String text) {
3+
HashMap<Character, Integer> map = new HashMap<>();
4+
5+
for (char ch : text.toCharArray()) {
6+
map.put(ch, map.getOrDefault(ch, 0) + 1);
7+
}
8+
9+
int res = Integer.MAX_VALUE;
10+
11+
res = Math.min(res, map.getOrDefault('b', 0));
12+
res = Math.min(res, map.getOrDefault('a', 0));
13+
res = Math.min(res, map.getOrDefault('n', 0));
14+
res = Math.min(res, map.getOrDefault('l', 0) / 2);
15+
res = Math.min(res, map.getOrDefault('o', 0) / 2);
16+
17+
return res;
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'''
2+
Given an integer n, return a string with n characters such that each character in such string occurs an odd number of times.
3+
The returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.
4+
Input: n = 4
5+
Output: "pppz"
6+
'''
7+
class Solution:
8+
def generateTheString(self, n: int) -> str:
9+
if n%2==0:
10+
return "a" * (n-1) + "b"
11+
else:
12+
return "a" * n

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy