高度平衡树理解零输入测试用例

时间:2019-06-27 00:37:38

标签: python algorithm

我正在尝试从leetcode解决一个算法问题。

  

给出一棵二叉树,确定它是否高度平衡。

     

对于此问题,高度平衡的二叉树定义为:

     

二叉树,其中每个节点的两个子树的深度   相差不超过1。

我的方法是收集节点的深度并进行比较。当差小于1(绝对值)时,返回1,否则返回False。如果没有root用户,则将其替换为0。

def get_playable_podcast(soup):
"""
@param: parsed html page            
"""
subjects = []

for content in soup.find_all('item'):

    try:        
        link = content.find('enclosure')
        link = link.get('url')
        print "\n\nLink: ", link

        title = content.find('title')
        title = title.get_text()

        desc = content.find('itunes:subtitle')
        desc = desc.get_text()

        thumbnail = content.find('itunes:image')
        thumbnail = thumbnail.get('href')

    except AttributeError:
        continue

    item = {
            'url': link,
            'title': title,
            'desc': desc,
            'thumbnail': thumbnail
    }

    subjects.append(item) 

return subjects

def compile_playable_podcast(playable_podcast):
"""
@para: list containing dict of key/values pairs for playable podcasts
"""
items = []

for podcast in playable_podcast:
    items.append({
        'label': podcast['title'],
        'thumbnail': podcast['thumbnail'],
        'path': podcast['url'],
        'info': podcast['desc'],
        'is_playable': True,
})

return items

不幸的是,该解决方案在非常原始的[]空测试输入上失败。我不清楚。我以为没有孩子,没有东西可比,因此为0。我是否从高度平衡树的定义中漏掉了一点东西?

0 个答案:

没有答案
相关问题