You are 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 an empty string "" if no odd integer exists.

A substring is a contiguous sequence of characters within a string.

&nbsp;
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.


&nbsp;
Constraints:


	1 &lt;= num.length &lt;= 105
	num only consists of digits and does not contain any leading zeros.


class Solution:
    def largestOddNumber(self, num: str) -> str:
        indx = -1
        n = len(num)
        for i in range(n):
            if int(num[i])%2 == 1:
                indx = i
        
        if indx == -1:
            return ""
        return num[:indx+1]
class Solution {
    public String largestOddNumber(String num) {
        for (int i = num.length() - 1; i > -1; i--) {
            if (num.charAt(i) % 2 == 1) return num.substring(0,i+1);
        }
        return "";
    }
}
class Solution {
public:
    string largestOddNumber(string num) {
        // Length of the given string
        int len = num.size();
        // We initialize an empty string for the result
        string res = "";
        // We start searching digits from the very right to left because we want to find the first odd digit
        // Which will be the last digit of our biggest odd number
        for (int i = len - 1; i >= 0; i--) {
            // Here we just convert char to an integer in C++
            // We can also do the reverse operation by adding '0' to an int to get char from an int
            int isOdd = num[i] - '0';
            // We check if the current digit is odd, if so this is the position we want to find
            if (isOdd % 2 == 1) {
                // Since we have found the correct spot, let's create our result string
                // We can basically extract the part starting from 0th index to right most odd digit's index
                // Like this:
                // 0123456 -> indices
                // 1246878 -> digits
                // ^....^ -> The part we extracted [0 to 5]
                res = num.substr(0, i + 1); // i+1 is length of substring
                // Because we know this would be the largest substring as we are starting from last
                // We can terminate the loop and return the result
                break;
            }
        }
        return res;
    }
};
var largestOddNumber = function(num) {
    for (let i = num.length - 1; i >= 0; i--) {
	    // +num[i] converts string into number like parseInt(num[i])
        if ((+num[i]) % 2) {
            return num.slice(0, i + 1);
        }
    }
    return '';
};
Largest Odd Number in String