当前位置:网站首页>2309. The best English letters with both upper and lower case
2309. The best English letters with both upper and lower case
2022-07-05 09:06:00 【Laver (nori)】
Ideas :
1. Use fixed length arrays , Store whether upper and lower case letters appear ;
2. Reverse traversal , Start with the big letters , Until you find the result ;
class Solution {
public:
string greatestLetter(string s) {
// A lowercase letter
vector<int> auxUpper(26, 0);
// Capitalization
vector<int> auxLower(26, 0);
// Traversal string s, Record the upper and lower case letters
for(auto ch : s){
if(ch >= 'A' && ch <= 'Z'){
// upper letter
auxUpper[(int)(ch - 'A')] = 1;
}else{
// lower letter
auxLower[(int)(ch - 'a')] = 1;
}
}
// Traverse in reverse order to find the first letter with both upper and lower case
for(int i = 25; i >= 0; i--){
if(auxUpper[i] == 1 && auxLower[i] == 1){
return string(1, (char)(i + 'A'));
}
}
return "";
}
};
边栏推荐
- 2309. 兼具大小写的最好英文字母
- golang 基础 ——map、数组、切片 存放不同类型的数据
- Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
- 深度学习模型与湿实验的结合,有望用于代谢通量分析
- Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
- 信息与熵,你想知道的都在这里了
- Halcon color recognition_ fuses. hdev:classify fuses by color
- Array, date, string object method
- C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
- Halcon blob analysis (ball.hdev)
猜你喜欢
Programming implementation of ROS learning 2 publisher node
Huber Loss
Confusion matrix
Applet (use of NPM package)
Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc
Nodemon installation and use
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
[daiy4] copy of JZ35 complex linked list
资源变现小程序添加折扣充值和折扣影票插件
随机推荐
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Halcon Chinese character recognition
AdaBoost use
[daiy4] jz32 print binary tree from top to bottom
使用arm Neon操作,提高内存拷贝速度
2011-11-21 training record personal training (III)
驾驶证体检医院(114---2 挂对应的医院司机体检)
scipy.misc.imread()
scipy. misc. imread()
Summary of "reversal" problem in challenge Programming Competition
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Codeworks round 681 (Div. 2) supplement
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
Array,Date,String 对象方法
2311. 小于等于 K 的最长二进制子序列
Halcon snap, get the area and position of coins
特征工程
图解网络:什么是网关负载均衡协议GLBP?
What is a firewall? Explanation of basic knowledge of firewall
Codeforces Round #648 (Div. 2) E.Maximum Subsequence Value