Skip to content

Instantly share code, notes, and snippets.

@liketheflower
Created December 16, 2019 15:49
Show Gist options
  • Save liketheflower/22f5bbaa537520a2b43cf491030a50f8 to your computer and use it in GitHub Desktop.
Save liketheflower/22f5bbaa537520a2b43cf491030a50f8 to your computer and use it in GitHub Desktop.
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