text: Generate all numbers up to N in Lexicographical Order | C # program for the above approach ; Driver code
code: 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 ) ; } public static void Main ( ) { int n = 15 ; lexNumbers ( n ) ; } }