解题思路 这个数字中有几个零就可以少删几步 所以只需要将数字转换为字符串类型,遍历字符串,检查数组中有几个零 最终几位数减去零的个数就是所需的步数、 代码如下
`def solution(n: int, a: list) -> int: total_steps = 0
# 遍历数组中的每个数字
for num in a:
# 计算当前数字的位数
# 提示:可以使用字符串长度来计算位数
num_digits = len(str(num))
for i in range(num_digits):
if str(num)[i]=='0':
num_digits-=1
# 累加到总步数
total_steps += num_digits
return total_steps`