题解 | #字符串通配符#

字符串通配符

https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036

s1, s2 = input().lower(), input().lower()
isMatch = [[False] * (len(s2) + 1)]
isMatch[0][0] = True

for i in range(1, len(s1) + 1):
    isMatch.append([False] * (len(s2) + 1))
    if s1[i - 1] == '*':
        isMatch[i][0] = isMatch[i - 1][0]
    for j in range(1, len(s2) + 1):
        if s1[i - 1] == s2[j - 1] or (s1[i - 1] == '?' and (s2[j - 1].isdigit() or s2[j - 1].isalpha())):
            isMatch[i][j] = isMatch[i - 1][j - 1]
        elif s1[i - 1] == '*':
            isMatch[i][j] = isMatch[i - 1][j] or (isMatch[i][j - 1] and (s2[j - 1].isdigit() or s2[j - 1].isalpha()))
if isMatch[-1][-1]:
    print('true')
else:
    print('false')

动态规划思路

全部评论

相关推荐

程序员牛肉:你这简历有啥值得拷打的?在牛客你这种简历一抓一大把,也就是个人信息不一样而已。 关键要去找亮点,亮点啊,整个简历都跟流水线生产出来的一样。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务