class Solution {
public:
void dfs(vector<int>& ans,int fa,long long path,int K,int& low,int& high,bool flag){
if(K==0){
if(path >= low && path <= high) ans.push_back(path);
return ;
}
if(flag){
dfs(ans,0,path*10,K-1,low,high,true);
for(int i=1;i<10;i++) dfs(ans,i,path*10+i,K-1,low,high,false);
return ;
}
if(fa-1 >= 0) dfs(ans,fa-1,path*10+fa-1,K-1,low,high,false);
if(fa+1 <= 9) dfs(ans,fa+1,path*10+fa+1,K-1,low,high,false);
}
vector<int> countSteppingNumbers(int low, int high) {
vector<int> ans;
int t = high;
int K = 0;
while(t>0){K++;t/=10;}
dfs(ans,0,0,K,low,high,true);
return ans;
}
};