题目三:二维数组查找:
1. list和array不同,取list的一列:
b=[x[0] for x in a]
2. 判断空list:
如果是[[]],这种会认为不是空
if not array or len(array[0]) == 0: return False
我的答案:
# -*- coding:utf-8 -*-
import unittest
class Solution:
# array 二维列表
def Find(self, target, array):
if not array or len(array[0]) == 0:
return False
if target > max(max(array)) or target < min(min(array)):
return False
if isinstance(target, int) is False:
return False
lne = 0
col = len(array[0])-1
while col >= 0 and lne < len(array):
chosen_num = array[lne][col]
if chosen_num == target:
print('found')
return True
elif chosen_num < target:
lne = lne + 1
else:
col = col - 1
print('not found')
return False
题目四:替换字符串中空格
1. 判断字符串:
if not a or isinstance(a, str) is False or len(a)<=0
题目五:替换字符串中空格
扫描二维码关注公众号,回复:
2993431 查看本文章