当前位置:网站首页>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 "";
}
};边栏推荐
- [daily training -- Tencent selected 50] 557 Reverse word III in string
- Bit operation related operations
- Golang foundation -- map, array and slice store different types of data
- AdaBoost use
- 皮尔森相关系数
- OpenFeign
- 3D reconstruction open source code summary [keep updated]
- Ros-11 common visualization tools
- notepad++
- Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
猜你喜欢

混淆矩阵(Confusion Matrix)

Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning

Summary of "reversal" problem in challenge Programming Competition

Ros-10 roslaunch summary

Programming implementation of ROS learning 2 publisher node
![[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b](/img/ee/8e07e2dd89bed63ff44400fe1864a9.jpg)
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b

Confusing basic concepts member variables local variables global variables

Numpy pit: after the addition of dimension (n, 1) and dimension (n,) array, the dimension becomes (n, n)

Halcon blob analysis (ball.hdev)

我从技术到产品经理的几点体会
随机推荐
notepad++
Ros-11 common visualization tools
优先级队列(堆)
js异步错误处理
Solutions of ordinary differential equations (2) examples
520 diamond Championship 7-4 7-7 solution
[daiy4] copy of JZ35 complex linked list
Multiple linear regression (sklearn method)
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
Halcon clolor_ pieces. Hedv: classifier_ Color recognition
Beautiful soup parsing and extracting data
【日常訓練--騰訊精選50】557. 反轉字符串中的單詞 III
Understanding rotation matrix R from the perspective of base transformation
Halcon blob analysis (ball.hdev)
Use arm neon operation to improve memory copy speed
特征工程
Array, date, string object method
Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc
Golang foundation - the time data inserted by golang into MySQL is inconsistent with the local time
asp. Net (c)