Time Complexity O(n) and Space complexity O(no. of digits in n * 10)


  • 0

    I am getting " Time Limit Exceeded". Please admin let me know my mistake.
    '''
    public class Solution {
    public List<Integer> lexicalOrder(int n) {

    	List<Integer> ar= LO(1,n);
    	return ar;
    }
    
    
    public static ArrayList<Integer> LO(int no,int value)
    {
    	ArrayList<Integer> ar=new ArrayList<>();
    	if(no<=value)
    	{	
    		for(int i=0;i<10;i++)
    		{
    			if(no+i <= value)
    			{
    				if(no==1 && i==9)
    				{
    					break;
    				}
    				ar.add(no+i);
    				ar.addAll(LO((no+i)*10,value));
    				
    				
    			}
    			else
    			{
    				break;
    			}
    			
    		}
    	}
    	return ar;
    }
    

    }
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.