problems(cpp): add “1903. Largest Odd Number in String”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
6cd1c84ebf
commit
ffa227587e
1 changed files with 13 additions and 0 deletions
13
problems/cpp/largest-odd-number-in-string.cpp
Normal file
13
problems/cpp/largest-odd-number-in-string.cpp
Normal 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);
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue