当前位置:网站首页>LeetCode 387. 字符串中的第一个唯一字符
LeetCode 387. 字符串中的第一个唯一字符
2022-08-01 04:49:00 【PUdd】
我的思路
建立26个字母的数组character[26],如a出现一次则character[0]==1;b出现则character[1]==1;a再出现一次则character[0]==2;
遍历过s后,只需再从头找一遍每个字母对应character数组中的出现次数,小于2就直接返回,如果全部找过一遍没有那就直接返回-1了。
代码
class Solution {
public:
int firstUniqChar(string s)
{
int character[26]={
0};
for(int i=0;i<s.length();i++)
{
character[(s[i]-97)]+=1;
}
for(int i=0;i<s.length();i++)
{
if(character[(s[i]-97)]<2 ) return i;
}
return -1;
}
};
边栏推荐
- 风险策略调优中重要的三步分析法
- 文件的异步读写
- [FPGA tutorial case 43] Image case 3 - image sobel edge extraction through verilog, auxiliary verification through MATLAB
- 【目标检测】YOLOv7理论简介+实践测试
- The kernel's handling of the device tree
- Valentine's Day Romantic 3D Photo Wall [with source code]
- 罗技鼠标体验记录
- 基于STM32设计的UNO卡牌游戏(双人、多人对战)
- Mysql基础篇(约束)
- MLP neural network, GRNN neural network, SVM neural network and deep learning neural network compare and identify human health and non-health data
猜你喜欢
FFmpeg 搭建本地屏幕录制环境
y83.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十四)
开源许可证 GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
IJCAI2022 | Hybrid Probabilistic Reasoning with Algebraic and Logical Constraints
故乡的素描画
Typescript20 - interface
今日睡眠质量记录68分
typescript23-元组
Simulation of Active anti-islanding-AFD Active Anti-islanding Model Based on Simulink
UE4 模型OnClick事件不生效的两种原因
随机推荐
PMP 项目质量管理
The method of solving stored procedure table name passing through variable in mysql
2022-07-31: Given a graph with n points and m directed edges, you can use magic to turn directed edges into undirected edges, such as directed edges from A to B, with a weight of 7.After casting the m
A way to deal with infinite debugger
数据比对功能调研总结
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
产品经理访谈 | 第五代验证码的创新与背景
Step by step hand tearing carousel Figure 3 (nanny level tutorial)
IJCAI2022 | Hybrid Probabilistic Reasoning with Algebraic and Logical Constraints
typescript19-对象可选参数
阿叶的目标
MySQL4
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
李迟2022年7月工作生活总结
mysql中解决存储过程表名通过变量传递的方法
Visual Studio提供的 Command Prompt 到底有啥用
最新 955 不加班的公司名单
Message Queuing Message Storage Design (Architecture Camp Module 8 Jobs)
The Flow Of Percona Toolkit pt-table-checksum
PMP 项目资源管理