当前位置:网站首页>leetcode2309. The best English letters with both upper and lower case (simple, weekly)
leetcode2309. The best English letters with both upper and lower case (simple, weekly)
2022-07-02 01:53:00 【Heavy garbage】
Optimize 1: When traversing , Go back and forth , Traversing a[] and b[] All for true, be return
Optimize 2: Optimize the space to O(1)
Specific ideas :
'A’65->90 97->122 122-65+1=58 Need to use 8 The bytes are long long Type to save status
add to ch:flag |= (ch - ‘A’)
Determine whether upper and lower case letters exist :flag =(flag>>(‘a’-‘A’) & flag) by true
obtain ans:‘A’ + (flag Number of digits :64 - __builtin_clzll(flag)) - 1
class Solution {
public:
string greatestLetter(string s) {
long long flag = 0;
for (auto& ch : s) {
flag |= (1ll << ch - 'A'); //
}
flag &= (flag >> ('a' - 'A'));
return flag ? string(1, 63 - __builtin_clzll(flag) + 'A') : "";
}
};
It's easy to get wrong :1ll Move left
边栏推荐
- MySQL view concept, create view, view, modify view, delete view
- Unity AssetBundle subcontracting
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- 2022 Q2 - Summary of skills to improve skills
- [Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
- 基于SSM实现微博系统
- Laravel artisan common commands
- 卷积神经网络(包含代码与相应图解)
- 城市选择器组件实现原理
- Laravel artisan 常用命令
猜你喜欢
II Basic structure of radio energy transmission system
成功实现边缘编码需要了解的六大经验教训
Feature extraction and detection 16 brisk feature detection and matching
What is AQS and its principle
leetcode373. 查找和最小的 K 对数字(中等)
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
Unity AssetBundle subcontracting
5g/4g pole gateway_ Smart pole gateway
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
How to use a product to promote "brand thrill"?
随机推荐
The difference between new and malloc
1218 square or round
matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音
Word search applet design report based on cloud development +ppt+ project source code + demonstration video
Selection of field types for creating tables in MySQL database
Feature extraction and detection 16 brisk feature detection and matching
Android: the kotlin language uses grendao3, a cross platform app development framework
new和malloc的区别
Redis环境搭建和使用的方法
321. Chessboard segmentation (2D interval DP)
matlab 使用 resample 完成重采样
Construction and maintenance of business websites [13]
如何用一款产品推动「品牌的惊险一跃」?
6-2 vulnerability exploitation - inevitable problems of FTP
正则表达式学习笔记
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
Unity AssetBundle subcontracting
1069. Division of convex polygons (thinking, interval DP)
II Basic structure of radio energy transmission system
MPLS experiment operation