C # program for the above approach
using System ; using System . Collections . Generic ; class GFG { public static void lexNumbers ( int n ) { List < int > sol = new List < int > ( ) ; dfs ( 1 , n , sol ) ; Console . WriteLine ( " [ " + string . Join ( " , ▁ " , sol ) + " ] " ) ; } public static void dfs ( int temp , int n , List < int > sol ) { if ( temp > n ) return ; sol . Add ( temp ) ; dfs ( temp * 10 , n , sol ) ; if ( temp % 10 != 9 ) dfs ( temp + 1 , n , sol ) ; }