diff --git a/cpp/2305/LC230509CN.cpp b/cpp/2305/LC230509CN.cpp new file mode 100644 index 0000000..62f6aea --- /dev/null +++ b/cpp/2305/LC230509CN.cpp @@ -0,0 +1,36 @@ +#include + +/** + * 2437. Number of Valid Clock Times + * + * You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59". + * In the string time, the digits represented by the ? symbol are unknown, and must be replaced with a digit from 0 to 9. + * Return an integer answer, the number of valid clock times that can be created by replacing every ? with a digit from 0 to 9. + */ + +class LC230509CN { +public: + static int countTime(const std::string&) noexcept; +}; + +bool match(const char* s, const char* t) { + for (; *s && *t; ++s, ++t) + if (*s != *t && *t != '?') + return false; + return true; +} + +int LC230509CN::countTime(const std::string& time) noexcept { + auto* time_ptr = time.c_str(); + char buf[8]; + int ret = 0; + for (int h = 0; h < 24; ++h) { + for (int m = 0; m < 60; ++m) { + std::sprintf(buf, "%02d:%02d", h, m); + ret += match(buf, time_ptr); + } + } + return ret; +} + +using Solution = LC230509CN; diff --git a/cpp/2305/defs.h b/cpp/2305/defs.h index 65f75ad..3e048b2 100644 --- a/cpp/2305/defs.h +++ b/cpp/2305/defs.h @@ -75,6 +75,11 @@ public: static std::vector longestObstacleCourseAtEachPosition(const std::vector&) noexcept; }; +class LC230507CN { +public: + static int numPairsDivisibleBy60(const std::vector&) noexcept; +}; + class LC230508 { public: static int diagonalSum(const std::vector>&) noexcept; @@ -89,4 +94,9 @@ public: static int minPushBox(const std::vector>&) noexcept; }; +class LC230509CN { +public: + static int countTime(const std::string&) noexcept; +}; + #endif //LEETCODE_CPP_DEFS_H