Skip to content

Latest commit

 

History

History

stepping-numbers

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

< Previous                  Next >

A Stepping Number is an integer such that all of its adjacent digits have an absolute difference of exactly 1. For example, 321 is a Stepping Number while 421 is not.

Given two integers low and high, find and return a sorted list of all the Stepping Numbers in the range [low, high] inclusive.

 

Example 1:

Input: low = 0, high = 21
Output: [0,1,2,3,4,5,6,7,8,9,10,12,21]

 

Constraints:

  • 0 <= low <= high <= 2 * 10^9

Related Topics

[Backtracking]

Hints

Hint 1 Try to generate the numbers using recursion.
Hint 2 In one step in the recursion, add a valid digit to the right of the current number.
Hint 3 Save the number if it's in the range between low and high.