剑指offer54:字符流中第一个不重复的字符
2024-08-26 18:39:34
1 题目描述
请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g"。当从该字符流中读出前六个字符“google"时,第一个只出现一次的字符是"l"。
输出描述:
如果当前字符流没有存在出现一次的字符,返回#字符。
2 思路和方法, C++核心代码
class Solution
{
public:
//Insert one char from stringstream
void Insert(char ch)
{
s = s + ch;
if(cha[ch])
cha[ch]++;
else
cha[ch] = ;
}
//return the first appearence once char in current stringstream
char FirstAppearingOnce()
{
int length = s.size();
for(int i=; i<length; i++){
if(cha[s[i]] == )
return s[i];
}
return '#';
}
private:
char cha[]={};
string s;
};
参考资料
https://blog.csdn.net/u012477435/article/details/83351659#_1529
最新文章
- 如何在ASP.NET MVC和EF中使用AngularJS
- [C++] Running time and Integer to String
- Windows下Nginx的启动、停止等命令
- Android开发之 adb 启动问题或是部署应用不成功,出现“The connection to adb is down, and a severe error has occured.”错误
- C++的异常处理
- 分享一个安卓中异步获取网络图片并自适应大小的第三方程序(来自github)
- Cloud Test 单页面即时监测功能上线!
- CSS伪类对象before和after的用法
- AngularJS自定义表单控件
- NVIDIA+关联2015写学校招收评论(嵌入式方向,上海)
- c# 实时监控数据库 SqlDependency
- Java Spring 在线程中或其他位置获取 ApplicationContext 或 ServiceBean
- JavaScript基础函数---李老师的
- Java_去除字符串空格
- Elasticsearch学习笔记(二)Search API 与 Query DSL
- Sequential Minimal Optimization (SMO) 算法
- set_magic_quotes_runtime set_magic_quotes_gpc
- springmvc返回json数据的工具类
- C语言条件编译
- 在Ubuntu下设置默认编辑器