1 Star 1 Fork 0

laodasbch/Leetcode-Complete-Guide

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1371.txt 913 Bytes
一键复制 编辑 原始数据 按行查看 历史
JunB(66哥) 提交于 2020-10-21 07:40 +08:00 . Rename 1317.txt to 1371.txt
思路:
bit+prefix sum
代码:
class Solution {
public:
int findTheLongestSubstring(string s) {
int res=0;
unordered_set<char>vowel={'a','e','i','o','u'};
unordered_map<int,int>hash;
vector<int>A(26);
for(int i=0;i<s.size();i++){
char c=s[i];
if(vowel.find(c)!=vowel.end()){
A[c-'a']++;
}
int bit=encode(A);
if(bit==0)res=max(res,i+1);
else{
if(hash.count(bit)!=0){
int index=hash[bit];
res=max(res,i-index);
}else{
hash[bit]=i;
}
}
}
return res;
}
int encode(vector<int>& A){
int res=0;
for(int i=0;i<A.size();i++){
if(A[i]%2==1)res=res|(1<<i);
}
return res;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/laodasbch/Leetcode-Complete-Guide.git
git@gitee.com:laodasbch/Leetcode-Complete-Guide.git
laodasbch
Leetcode-Complete-Guide
Leetcode-Complete-Guide
master

搜索帮助