LeetCode Entry

1903. Largest Odd Number in String

07.12.2023 easy 2023 kotlin

Largest odd number in a string

1903. Largest Odd Number in String easy blog post substack image.png

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/431

Problem TLDR

Largest odd number in a string

Intuition

Just search for the last odd

Approach

Let’s write Kotlin one-liner

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(n)\)

Code


  fun largestOddNumber(num: String): String =
    num.dropLastWhile { it.toInt() % 2 == 0 }