当前位置:网站首页>LeetCode 5242. 兼具大小写的最好英文字母
LeetCode 5242. 兼具大小写的最好英文字母
2022-06-22 00:37:00 【Michael阿明】
1. 题目
给你一个由英文字母组成的字符串 s ,请你找出并返回 s 中的 最好 英文字母。
返回的字母必须为大写形式。如果不存在满足条件的字母,则返回一个空字符串。
最好 英文字母的大写和小写形式必须 都 在 s 中出现。
英文字母 b 比另一个英文字母 a 更好 的前提是:英文字母表中,b 在 a 之 后 出现。
示例 1:
输入:s = "lEeTcOdE"
输出:"E"
解释:
字母 'E' 是唯一一个大写和小写形式都出现的字母。
示例 2:
输入:s = "arRAzFif"
输出:"R"
解释:
字母 'R' 是大写和小写形式都出现的最好英文字母。
注意 'A' 和 'F' 的大写和小写形式也都出现了,但是 'R' 比 'F' 和 'A' 更好。
示例 3:
输入:s = "AbCdEfGhIjK"
输出:""
解释:
不存在大写和小写形式都出现的字母。
提示:
1 <= s.length <= 1000
s 由小写和大写英文字母组成
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/greatest-english-letter-in-upper-and-lower-case
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2. 解题
- 利用set存储字符,检查 大小写字符是否都存在
class Solution:
def greatestLetter(self, s: str) -> str:
charset = set([c for c in s])
ans = ''
for c in [chr(ord('a')+i) for i in range(26)]:
if c in charset and chr(ord(c)-32) in charset:
ans = str(chr(ord(c)-32))
return ans
32 ms 15.2 MB Python3
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!
边栏推荐
- Unlovable STL
- IDEA提示 ‘Optional.get()‘ without ‘isPresent()‘ check错误。
- 動態規劃-01背包,分割等和子集,最後一塊石頭的重量
- FLowable运行时事务相关的表和表结构
- Install tensorflow and transformer on Orange Pie orangepi4b
- Differences among active window, focused window and foreground window
- Sparkrdd case: calculate total score
- Yolov3 3D semantic point cloud paper reading
- 从简单实例来看 left join 如何去重
- [ÑÖÏ Simulation Competition] fading (matrix acceleration, cyclic convolution, Gauss elimination)
猜你喜欢

【ÑÖÏ模拟赛】花萎(矩阵加速,循环卷积,高斯消元)

4g/wifi energy consumption metering socket - monitoring voltage, current and power

Error 4 opening dom ASM/Self in 0x8283c00

Pytorch learning 10: statistical operations

LVGL的一些介绍和移植

4G/wifi 能耗计量插座-监测电压电流功率

Pytorch learning 13: implement letnet and learning nn Module related basic operations

lvgl使用demo示例及说明1
![[dailyfresh] course record](/img/af/c1f4ed20606a70e4c59ba0b56562fb.png)
[dailyfresh] course record

Tensorflow环境搭建
随机推荐
2. add two numbers
Pytorch learning 10: statistical operations
[project construction] cmake create release and debug projects
LVGL的一些介绍和移植
[GLib][GStreamer] 插件编写思路 —— 继承、覆写 和 虚函数
Record the use process of webscraper
4275. Dijkstra sequence
Idea prompt 'optional Get() 'without' ispresent() 'check error.
记录webscraper的使用过程
Summary of new MySQL 8.0 features
Pytorch learning 09: basic matrix operations
Understanding the relationship between knowledge map and deep learning
Error 4 opening dom ASM/Self in 0x8283c00
. Several methods of obtaining hinstance in. Net
==And equals
[其他] 浅析ELF中的GOT与PLT
安装EasyX-VC2019
RNN的简单整理
聚宽 - 简单策略试验
LCP 17. 速算机器人