Largest Odd Number in String

Easy

Description

Given a string num representing a large integer, return the largest-valued odd integer (as a string) that is a non-empty substring of num, or empty string if no odd integer exists.

Examples

Input:num = "52"
Output:"5"
Explanation:

5 is the only odd number.

Input:num = "a"
Output:"5"
Explanation:

A single-digit number has only one odd digit to consider.

Input:num = "2468"
Output:""
Explanation:

All digits (2, 4, 6, 8) are even numbers, so no odd substring exists. Return empty string.

Constraints

  • 1 ≤ num.length ≤ 10^5

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!