Created
December 16, 2019 15:49
-
-
Save liketheflower/22f5bbaa537520a2b43cf491030a50f8 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
from functools import lru_cache | |
@lru_cache(None) | |
def abbreviation(a, b): | |
def dp(i,j): | |
if i==0 and j==0:return True | |
if i==0:return False | |
if j==0: | |
if a[i-1].islower():return dp(i-1, j) | |
else:return False | |
if a[i-1]==b[j-1]: | |
return dp(i-1, j-1) | |
elif a[i-1].upper()==b[j-1]: | |
return dp(i-1, j-1) or dp(i-1, j) | |
elif a[i-1].islower(): | |
return dp(i-1, j) | |
else: | |
return False | |
return 'YES' if dp(len(a),len(b)) else 'NO' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment