当前位置:网站首页>2022.07.24(LC_6124_第一个出现两次的字母)
2022.07.24(LC_6124_第一个出现两次的字母)
2022-07-25 11:45:00 【Leeli9316】

方法:计数
class Solution {
public char repeatedCharacter(String s) {
int[] counter = new int[26];
for (char ch : s.toCharArray()) {
counter[ch - 'a']++;
if (counter[ch - 'a'] > 1) {
return ch;
}
}
return 'a';
}
}方法二:哈希表
class Solution {
public char repeatedCharacter(String s) {
Set<Character> set = new HashSet<>();
for (char ch : s.toCharArray()) {
if (!set.add(ch)) {
return ch;
}
}
return 'a';
}
}边栏推荐
- Numpy first acquaintance
- monit安装和使用
- 3.2.1 what is machine learning?
- scrapy爬虫爬取动态网站
- Can't delete the blank page in word? How to operate?
- 想要做好软件测试,可以先了解AST、SCA和渗透测试
- PyTorch项目实战—FashionMNIST时装分类
- 【8】 Clever use of color finder
- Build a series of vision transformer practices, and finally meet, Timm library!
- R language uses the ggarrange function of ggpubr package to combine multiple images, and uses the ggexport function to save the visual images in JPEG format (width parameter specifies width, height pa
猜你喜欢

Brpc source code analysis (II) -- the processing process of brpc receiving requests

Hydrogen entrepreneurship competition | Liu Yafang, deputy director of the science and Technology Department of the National Energy Administration: building a high-quality innovation system is the cor

面试官:“同学,你做过真实落地项目吗?”

Azure Devops(十四) 使用Azure的私有Nuget仓库

NLP knowledge - pytorch, back propagation, some small pieces of notes for predictive tasks

Visualize the training process using tensorboard

MySQL exercise 2

Hystrix使用

MySQL练习二

2.1.2 机器学习的应用
随机推荐
MySQL exercise 2
Feign use
Hydrogen entrepreneurship competition | Liu Yafang, deputy director of the science and Technology Department of the National Energy Administration: building a high-quality innovation system is the cor
scrapy 爬虫框架简介
Go garbage collector Guide
Atomic atomic class
Feign使用
web编程(二)CGI相关
【6】 Map box settings
The first scratch crawler
Zuul gateway use
【4】 Layout view and layout toolbar usage
Implement anti-theft chain through referer request header
那些离开网易的年轻人
Can't delete the blank page in word? How to operate?
想要做好软件测试,可以先了解AST、SCA和渗透测试
R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(设置min.segment.length参数为Inf不添加标签线段)
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
Brpc source code analysis (II) -- the processing process of brpc receiving requests
cmake 学习使用笔记(二)库的生成与使用