当前位置:网站首页>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 左移
边栏推荐
- 2022 Q2 - Summary of skills to improve skills
- [rust web rokcet Series 2] connect the database and add, delete, modify and check curd
- 321. Chessboard segmentation (2D interval DP)
- 正则表达式学习笔记
- Using tabbar in wechat applet
- Construction and maintenance of business websites [12]
- np.where 和 torch.where 用法
- I Brief introduction of radio energy transmission technology
- [C #] use regular verification content
- Number of palindromes in C language (leetcode)
猜你喜欢

三分钟学会基础k线图知识

Number of palindromes in C language (leetcode)

leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
![[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing](/img/56/87bc8fca9ceeab6484f567f7231fdb.png)
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing

JMeter (II) - install the custom thread groups plug-in

【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享

迁移云计算工作负载的四个基本策略

Convolutional neural network (including code and corresponding diagram)

Feature extraction and detection 16 brisk feature detection and matching
![[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
随机推荐
Selection of field types for creating tables in MySQL database
How to debug apps remotely and online?
matlab 使用 audioread 、 sound 读取和播放 wav 文件
479. Additive binary tree (interval DP on the tree)
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
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
new和malloc的区别
基于SSM实现微博系统
Electronic Association C language level 1 33, odd even number judgment
Redis有序集合如何使用
自动浏览拼多多商品
leetcode373. 查找和最小的 K 对数字(中等)
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
1069. Division of convex polygons (thinking, interval DP)
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure Exercise 3
Redis环境搭建和使用的方法
Convolutional neural network (including code and corresponding diagram)
VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
跨域?同源?一次搞懂什么是跨域
Word search applet design report based on cloud development +ppt+ project source code + demonstration video