Give you a string of English letters s , Please find out and return to s The best English letters in . The returned letters must be in upper case . If there is no letter that meets the condition , Then return an empty string .
The uppercase and lowercase forms of the best English letters must be in s It appears that .
English letter b Than another English letter a Better premise is : In the English alphabet ,b stay a After that .
Input :s = “lEeTcOdE”
Output :“E”
explain :
Letter ‘E’ Is the only letter that appears in both uppercase and lowercase .
Input :s = “arRAzFif”
Output :“R”
explain :
Letter ‘R’ It is the best English letter in both uppercase and lowercase .
Be careful ‘A’ and ‘F’ Both uppercase and lowercase forms of , however ‘R’ Than ‘F’ and ‘A’ Better .
Input :s = “AbCdEfGhIjK”
Output :“”
explain :
There are no letters in both upper and lower case forms .
1 <= s.length <= 1000
s It consists of lowercase and uppercase English letters
class Solution:
def greatestLetter(self, s: str) -> str:
hash1 = Counter(s)
ans = []
for i in range(97, 123):
if hash1[chr(i)] > 0 and hash1[chr(i - 32)] > 0:
ans.append(chr(i))
if len(ans) == 0:
return ""
return ans[len(ans) - 1].upper()