当前位置:网站首页>HJ字符个数统计
HJ字符个数统计
2022-06-28 07:36:00 【有勇气的牛排】
知识点:字符串、哈希
描述
编写一个函数,计算字符串中含有的不同字符的个数。字符在 ASCII 码范围内(0~127,包括0和127),换行表示结束符,不算在字符里。不在范围内的不作统计。多个相同的字符只计算一次
例如,对于字符串 abaca 而言,有 a、b、c 三种不同的字符,因此输出3。
数据范围:1≤n≤500
输入描述:
输入一行没有空格的字符串。
输出描述:
输出 输入字符串 中范围在(0~127,包括0和127)字符的种数。
示例1
输入:abc
输出:3
输入:aaa
输出:1
牛客HJ python3
# 方法一 28ms
str_list = list(set(input())) # 输入、去重、转列表
# 开始计数
conut = 0
for i in str_list:
if 0 <= ord(i) <= 127: # 判断ASCII码 是否符合要求
conut += 1
print(conut)
# 方法二 30ms
str_list = list(set(input())) # 输入、去重、转列表
# 开始计数
res_list = []
for i in str_list:
if 0 <= ord(i) <= 127: # 判断ASCII码 是否符合要求
res_list.append(i)
print(len(res_list))
边栏推荐
- Practice of traffic recording and playback in vivo
- MySQL master-slave replication, detailed configuration, create unable to connect processing prompt
- Unity UI shadow component
- Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
- MMR重排(相似度通过编辑距离和重复度计算)
- Mysql8.0和Mysql5.0访问jdbc连接
- Flutter realizes the function of "shake"
- Devtools implementation principle and performance analysis practice
- Design and implementation of spark offline development framework
- 什么是EC鼓风机(ec blower fan)?
猜你喜欢

Practice of traffic recording and playback in vivo

MySQL installation steps - installing MySQL on Linux (3)

Devtools implementation principle and performance analysis practice

Leetcode learning records

剑指Offer||:链表(简单)

Principle and practice of bytecode reference detection

Yesterday, I went to a large factory for an interview and asked me to do four arithmetic operations. Fortunately, I am smart enough

8 figures | analyze Eureka's first synchronization registry

MySQL master-slave replication, detailed configuration, create unable to connect processing prompt

Source code analysis of kubernetes' process of deleting pod
随机推荐
R and RGL draw 3D knots
阿里云服务器创建快照、回滚磁盘
看似简单的光耦电路,实际使用中应该注意些什么?
A single node obtains the lock lock of the order number
Redis implements distributed locks
Practice and exploration of vivo live broadcast application technology
什么是EC鼓风机(ec blower fan)?
R 语言 ggmap 可视化集群
Dbeaver 22.1.1 release, visual database management platform
MMR重排(相似度通过编辑距离和重复度计算)
OPC 协议认识
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Reading notes - MySQL technology l act: InnoDB storage engine (version 2)
Leetcode learning records
ABAP 技能树
SQL statement optimization steps (1)
Implementation of commit message standardized control in large projects
Block transmission by golang gin framework
Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio
Vivo browser rapid development platform practice - Overview