2309. Greatest English Letter in Upper and Lower Case
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 71% Topics: Hash Table, String, Enumeration
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
# string, hash table
class Solution(object):
def greatestLetter(self, s):
"""
:type s: str
:rtype: str
"""
lookup = set(s)
result = ""
for c in s:
if c.isupper() and lower(c) in s:
if c > result:
result = c
return result
# Time: O(n)
# Space: O(1)
import itertools
import string
# string, hash table
class Solution2(object):
def greatestLetter(self, s):
"""
:type s: str
:rtype: str
"""
lookup = set(s)
return next((C for c, C in itertools.izip(reversed(string.ascii_lowercase), reversed(string.ascii_uppercase)) if c in lookup and C in lookup), "")
Solution from kamyu104/LeetCode-Solutions · MIT