当前位置:网站首页>leetcode2309. 兼具大小写的最好英文字母(简单,周赛)
leetcode2309. 兼具大小写的最好英文字母(简单,周赛)
2022-07-02 01:51:00 【重you小垃】
优化1:遍历的时候,从后往前遍历,遍历到a[]和b[]都为true,则return
优化2: 用位运算将空间优化到O(1)
具体思路:
'A’65->90 97->122 122-65+1=58 需要用8字节也就是long long类型来存状态
添加ch:flag |= (ch - ‘A’)
判断大小写字母存在:flag =(flag>>(‘a’-‘A’) & flag)为true
得到ans:‘A’ + (flag的位数: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') : "";
}
};
易错点:1ll 左移
边栏推荐
- Construction and maintenance of business websites [10]
- 大学的知识是否学而无用、过时?
- Failed to transform file 'xxx' to match attributes
- [Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
- Is the knowledge of University useless and outdated?
- 电子协会 C语言 1级 33 、奇偶数判断
- 如何远程、在线调试app?
- Have you stepped on the nine common pits in the e-commerce system?
- Three core problems of concurrent programming
- 跨域?同源?一次搞懂什么是跨域
猜你喜欢
[Maya] the error of importing Maya into Metahuman
Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Volume compression, decompression
现货黄金分析的技巧有什么呢?
企业应该选择无服务器计算吗?
JMeter (II) - install the custom thread groups plug-in
TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
SQLite 3 of embedded database
随机推荐
卷积神经网络(包含代码与相应图解)
Using mongodb in laravel
Redis环境搭建和使用的方法
Number of palindromes in C language (leetcode)
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
Parted command
I Brief introduction of radio energy transmission technology
734. Energy stone (greed, backpack)
Regular expression learning notes
Unity AssetBundle subcontracting
ES6 new method of string
Failed to transform file 'xxx' to match attributes
人工智能在网络安全中的作用
Construction and maintenance of business websites [11]
电子协会 C语言 1级 32、计算2的幂
Have you stepped on the nine common pits in the e-commerce system?
Five skills of adding audio codec to embedded system
1217 supermarket coin processor
1069. Division of convex polygons (thinking, interval DP)
迁移云计算工作负载的四个基本策略