LeetCode solutions

2032. Largest Odd Number in String

My accepted Python solution to LeetCode problem 2032, Largest Odd Number in String, running in 10ms.

  • Difficulty: Easy
  • Python
  • Runtime 10ms
  • Memory 18.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 10ms, memory 18.3MB, accepted 2025-12-31.

python
class Solution:
    def largestOddNumber(self, num: str) -> str:
        for i in range(len(num) - 1, -1, -1):
            if int(num[i]) % 2 == 1:
                return num[:i+1]
        return ""

Source