示例#1
0
 def test_next_greatest_letter(self):
     letters = ["c", "f", "j"]
     target = "a"
     self.assertEqual("c", next_greatest_letter(letters, target))
     self.assertEqual("c", next_greatest_letter_v1(letters, target))
     self.assertEqual("c", next_greatest_letter_v2(letters, target))
     letters = ["c", "f", "j"]
     target = "d"
     self.assertEqual("f", next_greatest_letter(letters, target))
     self.assertEqual("f", next_greatest_letter_v1(letters, target))
     self.assertEqual("f", next_greatest_letter_v2(letters, target))
     letters = ["c", "f", "j"]
     target = "j"
     self.assertEqual("c", next_greatest_letter(letters, target))
     self.assertEqual("c", next_greatest_letter_v1(letters, target))
     self.assertEqual("c", next_greatest_letter_v2(letters, target))
letters = ['a', 'b'], the answer is 'a'.
Input:
letters = ["c", "f", "j"]
target = "a"
Output: "c"
Input:
letters = ["c", "f", "j"]
target = "c"
Output: "f"
Input:
letters = ["c", "f", "j"]
target = "d"
Output: "f"
Reference: https://leetcode.com/problems/find-smallest-letter-greater-than-target/description/
'''
from algorithms.search import next_greatest_letter,next_greatest_letter_v1,next_greatest_letter_v2
letters = ["c", "f", "j"]
target = "a"

print(next_greatest_letter(letters,target))


print(next_greatest_letter_v1(letters,target))


print(next_greatest_letter_v2(letters,target))