Ground for the House[去掉行列]

把每一行是纯0的去掉,就是了

def house(plan):
    #replace this for solution
    if '#'not in plan:return 0 

    str_1=plan.split()

    column_1 =len(str_1)
    row_1 = len(str_1[0])

    column_min=100
    column_max=0
    row_min=100
    row_max=0
    # 对行进行处理
    for x in range(column_1):
        if '#'in str_1[x] :
            if row_min>x:
                row_min=x 
            if row_max<x:
                row_max=x 
                
	# 对列进行处理
    str_2=['']* row_1

    for x in str_1:
        for y in range(row_1):
            str_2[y]+=x[y]

    for x in range(row_1):
        if '#'in str_2[x] :
            if column_min >x:
                column_min =x 
            if column_max<x:
                column_max=x 

    return (column_max- column_min)*(row_max- row_min)

if __name__ == '__main__':
    print("Example:")
    print(house('''
0000000
##00##0
######0
##00##0
#0000#0
'''))

    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert house('''
0000000
##00##0
######0
##00##0
#0000#0
''') == 24

    assert house('''0000000000
#000##000#
##########
##000000##
0000000000
''') == 30

    assert house('''0000
0000
#000
''') == 1

    assert house('''0000
0000
''') == 0

    assert house('''
0##0
0000
#00#
''') == 12

    print("Coding complete? Click 'Check' to earn cool rewards!")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值