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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 10ms, memory 18.3MB, accepted 2025-12-31.
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 ""