#1903
Largest Odd Number in String
pupil · 315 · lc easy +21 · premium · verified · 67% accepted · 2,567 likes · top 73%
Description
Given a string num representing a large non-negative integer, return the largest-valued odd number that is a non-empty substring of num, or an empty string if no such substring exists.
Example 1:
Input: num = "52"
Output: "5"
Explanation: The only non-empty substrings are "5", "2", and "52". "5" is the only odd number.
Example 2:
Input: num = "4206"
Output: ""
Explanation: There are no odd numbers in "4206".
Example 3:
Input: num = "35427"
Output: "35427"
Explanation: "35427" is already an odd number.
Code
1
2
3