add: 220213-CN

This commit is contained in:
Lam Haoyin 2022-02-13 00:25:29 +08:00
parent 90d06ec7ca
commit e2d1e288b0
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 42 additions and 1 deletions

41
2202/220213-CN.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <string>
/**
* 1189. Maximum Number of Balloons
* Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
* You can use each character in text at most once. Return the maximum number of instances that can be formed.
*/
class Solution {
public:
static int maxNumberOfBalloons(const std::string& text) {
int b = 0, a = 0, l = 0, o = 0, n = 0;
for (char ch : text) {
switch (ch) {
case 'b':
++b;
break;
case 'a':
++a;
break;
case 'l':
++l;
break;
case 'o':
++o;
break;
case 'n':
++n;
break;
default:;
}
}
l /= 2;
o /= 2;
return std::min(b, std::min(a, std::min(l, std::min(o, n))));
}
};
int main() {
return 0;
}

View File

@ -3,4 +3,4 @@ PROJECT(2202)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2202 220212.cpp) ADD_EXECUTABLE(2202 220213-CN.cpp)