当前位置:网站首页>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
边栏推荐
- Deep learning: a solution to over fitting in deep neural networks
- Failed to transform file 'xxx' to match attributes
- 机器学习基本概念
- Construction and maintenance of business websites [14]
- TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
- 现货黄金分析的技巧有什么呢?
- Should enterprises choose server free computing?
- 人工智能在网络安全中的作用
- Matlab uses audioread and sound to read and play WAV files
- 1217 supermarket coin processor
猜你喜欢
The technology boss is ready, and the topic of position C is up to you
如何远程、在线调试app?
What are the skills of spot gold analysis?
MySQL view concept, create view, view, modify view, delete view
三分钟学会基础k线图知识
【LeetCode 43】236. The nearest common ancestor of binary tree
Have you stepped on the nine common pits in the e-commerce system?
Ks006 student achievement management system based on SSM
k线图形态这样记(口诀篇)
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
随机推荐
Design and implementation of radio energy transmission system
1218 square or round
ES6 new method of string
What are the skills of spot gold analysis?
Basic concepts of machine learning
479. Additive binary tree (interval DP on the tree)
Software No.1
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
迁移云计算工作负载的四个基本策略
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure
Construction and maintenance of business websites [13]
Learn about servlets
np. Where and torch Where usage
KS006基于SSM实现学生成绩管理系统
Word search applet design report based on cloud development +ppt+ project source code + demonstration video
k线图形态这样记(口诀篇)
Self drawing of menu items and CListBox items
Ks006 student achievement management system based on SSM
matlab 使用 resample 完成重采样
Electronic Society C language level 1 32, calculate the power of 2