Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luojiyin1987/c4181132d02f78c3423bc55406e1c752 to your computer and use it in GitHub Desktop.
Save luojiyin1987/c4181132d02f78c3423bc55406e1c752 to your computer and use it in GitHub Desktop.
Find Smallest Letter Greater Than Target
class Solution(object):
def nextGreatestLetter(self, letters, target):
"""
:type letters: List[str]
:type target: str
:rtype: str
"""
letters = set(map(ord, letters))
for x in range(1, 27):
candidate = ord(target) + x
if candidate > ord('z'):
candidate -= 26
if candidate in letters:
return chr(candidate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment