当前位置:网站首页>2309. 兼具大小写的最好英文字母
2309. 兼具大小写的最好英文字母
2022-07-05 08:57:00 【紫菜(Nori)】
思路:
1.使用固定长度的数组,存储大小写字母是否出现;
2.倒序遍历,从字母大的开始遍历,直到找到结果;
class Solution {
public:
string greatestLetter(string s) {
// 小写
vector<int> auxUpper(26, 0);
// 大写
vector<int> auxLower(26, 0);
// 遍历字符串s,记录其中的大小写字母
for(auto ch : s){
if(ch >= 'A' && ch <= 'Z'){
// upper letter
auxUpper[(int)(ch - 'A')] = 1;
}else{
// lower letter
auxLower[(int)(ch - 'a')] = 1;
}
}
// 倒序遍历找到第一个大小写都存在的字母
for(int i = 25; i >= 0; i--){
if(auxUpper[i] == 1 && auxLower[i] == 1){
return string(1, (char)(i + 'A'));
}
}
return "";
}
};
边栏推荐
- [formation quotidienne - Tencent Selection 50] 557. Inverser le mot III dans la chaîne
- asp. Net (c)
- Attention is all you need
- Halcon affine transformations to regions
- My university
- TF coordinate transformation of common components of ros-9 ROS
- Halcon snap, get the area and position of coins
- How to manage the performance of R & D team?
- Causes and appropriate analysis of possible errors in seq2seq code of "hands on learning in depth"
- Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
猜你喜欢
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
Introduction Guide to stereo vision (5): dual camera calibration [no more collection, I charge ~]
Rebuild my 3D world [open source] [serialization-1]
Ros-10 roslaunch summary
Halcon snap, get the area and position of coins
Install the CPU version of tensorflow+cuda+cudnn (ultra detailed)
How to manage the performance of R & D team?
[matlab] matlab reads and writes Excel
什么是防火墙?防火墙基础知识讲解
RT-Thread内核快速入门,内核实现与应用开发学习随笔记
随机推荐
asp. Net (c)
Codeworks round 638 (Div. 2) cute new problem solution
【日常训练】1200. 最小绝对差
Dynamic dimensions required for input: input, but no shapes were provided. Automatically overriding
Halcon color recognition_ fuses. hdev:classify fuses by color
Infix expression evaluation
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Hello everyone, welcome to my CSDN blog!
Golang foundation -- map, array and slice store different types of data
JS asynchronous error handling
kubeadm系列-01-preflight究竟有多少check
Understanding rotation matrix R from the perspective of base transformation
Codeworks round 681 (Div. 2) supplement
皮尔森相关系数
C [essential skills] use of configurationmanager class (use of file app.config)
golang 基础 —— golang 向 mysql 插入的时间数据和本地时间不一致
asp.net(c#)的货币格式化
AdaBoost use
Dynamic dimensions required for input: input, but no shapes were provided. Automatically overriding
我从技术到产品经理的几点体会