当前位置:网站首页>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
边栏推荐
- 三分钟学会基础k线图知识
- Three core problems of concurrent programming
- Deep learning: a solution to over fitting in deep neural networks
- 6-2 vulnerability exploitation - inevitable problems of FTP
- Experimental reproduction of variable image compression with a scale hyperprior
- 如何用一款产品推动「品牌的惊险一跃」?
- MPLS experiment operation
- It's already 30. Can you learn programming from scratch?
- 电子协会 C语言 1级 33 、奇偶数判断
- Design and implementation of key value storage engine based on LSM tree
猜你喜欢

Word search applet design report based on cloud development +ppt+ project source code + demonstration video

Medical management system (C language course for freshmen)

MySQL主从延迟问题怎么解决
![[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing](/img/ba/dcb276768b1a9cc84099f093677d29.png)
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing

Number of palindromes in C language (leetcode)

Matlab uses resample to complete resampling

New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port

The concept, function, characteristics, creation and deletion of MySQL constraints

MySQL约束与多表查询实例分析

MySQL如何解决delete大量数据后空间不释放的问题
随机推荐
SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
Game thinking 15: thinking about the whole region and sub region Services
Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages
Failed to transform file 'xxx' to match attributes
Makefile simple induction
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
Basic concepts of machine learning
Selection of field types for creating tables in MySQL database
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
MySQL中一条SQL是怎么执行的
Construction and maintenance of business websites [15]
Niuke - Huawei question bank (51~60)
Construction and maintenance of business websites [13]
Cross domain? Homology? Understand what is cross domain at once
leetcode2312. 卖木头块(困难,周赛)
Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
Android: the kotlin language uses grendao3, a cross platform app development framework
II Basic structure of radio energy transmission system
D discard the virtual recovery method
电子协会 C语言 1级 32、计算2的幂