From e2d1e288b0c8d451391914e911a72aa2c9e899fb Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Sun, 13 Feb 2022 00:25:29 +0800 Subject: [PATCH] add: 220213-CN --- 2202/220213-CN.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2202/CMakeLists.txt | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 2202/220213-CN.cpp diff --git a/2202/220213-CN.cpp b/2202/220213-CN.cpp new file mode 100644 index 0000000..a966916 --- /dev/null +++ b/2202/220213-CN.cpp @@ -0,0 +1,41 @@ +#include + +/** + * 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; +} diff --git a/2202/CMakeLists.txt b/2202/CMakeLists.txt index 5172c6e..c9cf3eb 100644 --- a/2202/CMakeLists.txt +++ b/2202/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2202) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2202 220212.cpp) +ADD_EXECUTABLE(2202 220213-CN.cpp)