Step Number from 10 to N using python

后端 未结 4 1653
春和景丽
春和景丽 2021-01-21 18:04

The Program must accept an integer N. The program must print all the stepping number from 10 to N, if there is no such number present the program should print -1 as

4条回答
  •  心在旅途
    2021-01-21 18:33

    Since I can't comment yet. I will explain the idea of Nick's algorithm here.

    1. Create 1-digit number list [1,2,3,4,5,6,7,8,9]

    2. Create 2-digit number list by combining number k in 1-digit number list with k*10 + (k-1) or k*10 + (k+1), for example 3 will generate 32 or 34

    3. Repeat the step 2 until reaches m-digit number. m is calculated before.

提交回复
热议问题