python dfs


  • 0
    S
    def __init__(self, nestedList):
    
    	def dfs(res, listt):
    		if not listt:
    			return
    		for nest in listt:
    			if nest.isInteger():
    				res.append(nest.getInteger())
    			else:
    				newlist = nest.getList()
    				dfs(res, newlist)
    				
    	res = []
    	dfs(res, nestedList)
    	self.nums = res[::-1]
    
    def next(self):
    	return self.nums.pop()
    	
    def hasNext(self):
    	if self.nums:
    		return True
    	return False
    

Log in to reply
 

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