其他分享
首页 > 其他分享> > 统计一致字符串的数目

统计一致字符串的数目

作者:互联网

给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed 中,就称这个字符串是 一致字符串 。
来源:力扣(LeetCode)--1684
题解:在words多维字符元素中,每当一个元素,即一个一维数组都是由allowed中元素组成,一致字符串数量就加1

y_num = 0
allowed = input('请输入allowed:')
x_list = input('请输入words(以空格隔开):')
lt = [str(n) for n in x_list.split()]
for i in range(len(lt)):
x_num = 0
for j in lt[i]:
if j not in allowed:
x_num = 1
if x_num == 0:
y_num += 1
print('一致字符串的数目是:',y_num)

 


 

 

标签:字符,words,lt,num,一致,allowed,字符串,数目
来源: https://www.cnblogs.com/golden-tea/p/15723328.html