class Solution:
def nextGreatestLetter(self, letters, target):
"""
:type letters: List[str]
:type target: str
:rtype: str
"""
# method one ord(),chr()函数 , 没有充分利用letters有序这个条件
# ascii_target = ord(target)
# while ascii_target:
# ascii_target += 1
# if ascii_target > 122:
# ascii_target -= 26
# if chr(ascii_target) in letters:
# return chr(ascii_target)
# method two 直接比较字符大小(letters有序)
for letter in letters:
if letter > target:
return letter
return letters[0]
leetcode 744 Find Smallest Letter Greater Than Target 寻找比目标字母大的最小字母 python 多种思路 ord(),chr()
猜你喜欢
转载自blog.csdn.net/huhehaotechangsha/article/details/80851707
今日推荐
周排行