当前位置:网站首页>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 "";
}
};
边栏推荐
- Beautiful soup parsing and extracting data
- Array, date, string object method
- 我从技术到产品经理的几点体会
- Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning
- How to manage the performance of R & D team?
- Array,Date,String 对象方法
- [牛客网刷题 Day4] JZ35 复杂链表的复制
- Numpy pit: after the addition of dimension (n, 1) and dimension (n,) array, the dimension becomes (n, n)
- 牛顿迭代法(解非线性方程)
- Shift operation of complement
猜你喜欢
Hello everyone, welcome to my CSDN blog!
Redis implements a high-performance full-text search engine -- redisearch
什么是防火墙?防火墙基础知识讲解
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
我从技术到产品经理的几点体会
容易混淆的基本概念 成员变量 局部变量 全局变量
编辑器-vi、vim的使用
牛顿迭代法(解非线性方程)
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
混淆矩阵(Confusion Matrix)
随机推荐
容易混淆的基本概念 成员变量 局部变量 全局变量
[code practice] [stereo matching series] Classic ad census: (4) cross domain cost aggregation
Return of missing persons
Array, date, string object method
Mengxin summary of LIS (longest ascending subsequence) topics
My experience from technology to product manager
Latex improve
js异步错误处理
Install the CPU version of tensorflow+cuda+cudnn (ultra detailed)
The location search property gets the login user name
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
Infix expression evaluation
[Niuke brush questions day4] jz55 depth of binary tree
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Programming implementation of ROS learning 5-client node
Programming implementation of ROS learning 2 publisher node
[daiy4] copy of JZ35 complex linked list
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
Introduction Guide to stereo vision (7): stereo matching
Basic number theory -- Euler function