[python] Dynamic Programming > Abbreviation

이희진·2022년 12월 2일
0
#!/bin/python3

import math
import os
import random
import re
import sys

def isEqual(a, b):
    return a == b or a.upper() == b

def abbreviation(a, b):
    DP = []
    for i in range(len(a)+1):
        DP.append([False]*(len(b)+1))
    DP[0][0] = True
    
    for i in range(1, len(a)+1):
        for j in range(0, len(b)+1):
            if j > 0 and DP[i-1][j-1] and isEqual(a[i-1], b[j-1]):
                DP[i][j] = True
            if ord(a[i - 1]) >= 97 and DP[i - 1][j]:
                DP[i][j] = True
    if DP[len(a)][len(b)]:
        return 'YES'
    else:
        return 'NO'
    

0개의 댓글