Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.
You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2.
The array will always contain letters in only one case.
Example:
['a','b','c','d','f'] -> 'e'
['O','Q','R','S'] -> 'P'
這道題當時做的比較糾結,主要是chr()和ord()的用法,還要注意i的取值範圍問題,超出列表就不適用!
def find_missing_letter(chars):
for i in range(len(chars)-1):
if ord(chars[i])+1 != ord(chars[i+1]):
return chr(ord(chars[i])+1)