Last active
December 16, 2019 15:33
-
-
Save liketheflower/884d36ededf518b38bff2b41dcef1b9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def abbreviation(a, b): | |
m, n = len(a), len(b) | |
dp = [[False]*(m+1) for _ in range(n+1)] | |
dp[0][0] = True | |
for j in range(1, m+1): | |
if a[j-1].islower(): | |
dp[0][j] = dp[0][j-1] | |
for i in range(1, n+1): | |
for j in range(1,m+1): | |
if a[j-1] == b[i-1]: | |
dp[i][j] = dp[i-1][j-1] | |
elif a[j-1].upper() == b[i-1]: | |
dp[i][j] = dp[i-1][j-1] or dp[i][j-1] | |
elif a[j-1].islower(): | |
dp[i][j] = dp[i][j-1] | |
return "YES" if dp[n][m] else "NO" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment