Last active
December 16, 2019 15:04
-
-
Save liketheflower/d1c192646ba5b6bde63ce555e3d89e14 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(a,b): | |
if not a and not b:return True | |
if not a and b:return False | |
if not b and a:return all(ss.islower() for ss in a) | |
if len(a) ==1 and len(b)==1: | |
if a.upper()==b:return True | |
else:return False | |
if a[-1].isupper(): | |
if a[-1]!=b[-1]: | |
return False | |
else: | |
return dp(a[:-1], b[:-1]) | |
else: | |
if a[-1].upper()!=b[-1]: | |
return dp(a[:-1], b) | |
else: | |
return dp(a[:-1], b[:-1]) or dp(a[:-1], b) | |
return 'YES' if dp(a,b) else 'NO' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment