My Python solution to this.

def findSteppingNumbersOptimized(N, M): digits = [] for x in range(N,M+1): copyx = x steppingDigit = True currentDigit = x%10 x = x // 10 nextDigit = x%10 while x != 0 and steppingDigit == True: if abs(currentDigit -nextDigit) != 1: steppingDigit = False currentDigit = nextDigit x = x//10 nextDigit = x%10 if steppingDigit == True: digits.append(copyx) return digits