Created
August 12, 2018 09:41
-
-
Save luojiyin1987/c4181132d02f78c3423bc55406e1c752 to your computer and use it in GitHub Desktop.
Find Smallest Letter Greater Than Target
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
| 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