当前位置:网站首页>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
边栏推荐
- The technology boss is ready, and the topic of position C is up to you
- TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
- 牛客网——华为题库(51~60)
- 跨域?同源?一次搞懂什么是跨域
- Implementation of Weibo system based on SSM
- Is the knowledge of University useless and outdated?
- 【LeetCode 43】236. The nearest common ancestor of binary tree
- [rust web rokcet Series 1] Hello, world and get, post, put, delete
- np.where 和 torch.where 用法
- Openssl3.0 learning XXI provider encoder
猜你喜欢

PR second training

k线图形态这样记(口诀篇)

Penser au jeu 15: penser au service complet et au sous - service

Implementation of Weibo system based on SSM

人工智能在网络安全中的作用

II Basic structure of radio energy transmission system

MySQL如何解决delete大量数据后空间不释放的问题

Volume compression, decompression

matlab 使用 audioread 、 sound 读取和播放 wav 文件

【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
随机推荐
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility
Based on configured schedule, the given trigger will never fire
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Discussion on the idea of platform construction
1069. Division of convex polygons (thinking, interval DP)
现货黄金分析的技巧有什么呢?
mysql列转行函数指的是什么
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
Feature extraction and detection 16 brisk feature detection and matching
Construction and maintenance of business websites [11]
Construction and maintenance of business websites [10]
Based on configured schedule, the given trigger will never fire
The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu
企业应该选择无服务器计算吗?
Implementation of Weibo system based on SSM
1222. Password dropping (interval DP, bracket matching)
Self drawing of menu items and CListBox items
Regular expression learning notes
Niuke - Huawei question bank (51~60)