problems(cpp): add “1903. Largest Odd Number in String”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-12-07 16:16:08 +01:00
parent 6cd1c84ebf
commit ffa227587e
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,13 @@
#include <string>
class Solution {
public:
std::string largestOddNumber(const std::string& num) {
auto i = num.find_last_of("13579");
if (i == std::string::npos) {
return "";
}
return num.substr(0, i + 1);
}
};