A number would be odd if the number at the unit place num[-1]
is odd. Check from the end of the string, once we come across an odd number, we stop and return.
Code:
Python3
Big O Analysis
-
Runtime
The runtime complexity here is where N = length of string
num
. -
Memory
The memory usage is
O(1)
since we don’t use any linear or non-linear data structure.
— A