当前位置:网站首页>HJ character count
HJ character count
2022-06-28 07:38:00 【Courageous steak】
Knowledge point : character string 、 Hash
describe
Write a function , Count the number of different characters in the string . The characters are in ASCII Code range (0~127, Include 0 and 127), Line break means end , Not included in the characters . Statistics will not be made for those out of scope . Multiple identical characters count only once
for example , For strings abaca for , Yes a、b、c Three different characters , So output 3.
Data range :1≤n≤500
Input description :
Enter a line of string without spaces .
Output description :
Output Input string The middle range is (0~127, Include 0 and 127) Number of characters .
Example 1
Input :abc
Output :3
Input :aaa
Output :1
Cattle guest HJ python3
# Method 1 28ms
str_list = list(set(input())) # Input 、 duplicate removal 、 To list
# Start counting
conut = 0
for i in str_list:
if 0 <= ord(i) <= 127: # Judge ASCII code Whether it meets the requirements
conut += 1
print(conut)
# Method 2 30ms
str_list = list(set(input())) # Input 、 duplicate removal 、 To list
# Start counting
res_list = []
for i in str_list:
if 0 <= ord(i) <= 127: # Judge ASCII code Whether it meets the requirements
res_list.append(i)
print(len(res_list))
Link to the original text :
https://www.920vip.net/article/175
边栏推荐
- Code submission specification
- Understanding of OPC protocol
- How to configure DDR3 of dm8148
- Source code analysis of kubernetes' process of deleting pod
- 阿里云服务器创建快照、回滚磁盘
- Devtools implementation principle and performance analysis practice
- 股票炒股注册开户靠谱吗?安全吗?
- Porting ucosiii to stm32f429
- Mysql57 zip file installation
- Makefile
猜你喜欢
![[thanos source code analysis series]thanos query component source code analysis](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[thanos source code analysis series]thanos query component source code analysis

Rediscluster cluster mode capacity expansion node

A gadget can write crawlers faster

kubernetes删除pod的流程的源码简析

8 figures | analyze Eureka's first synchronization registry

mysql57 zip文件安装

The practice of event driven architecture in vivo content platform

kubernetes集群命令行工具kubectl

阿里云服务器创建快照、回滚磁盘

kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
随机推荐
Can okcc call centers work without computers?
阿里云服务器创建快照、回滚磁盘
同花顺网上开户安全吗
"Three routines" of digital collection market
Solving the longest palindrome substring by dynamic programming
Design of DSP image data stream
R and RGL draw 3D knots
Devtools implementation principle and performance analysis practice
NDK cross compilation
7-1 understand everything
云原生(待更新)
2021 programming language ranking summary
看似简单的光耦电路,实际使用中应该注意些什么?
es数据导出csv文件
ABAP 技能树
Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
Alibaba cloud server creates snapshots and rolls back disks
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
Introduction and several months' experience of extending the solution thanos of Prometheus
安全培训是员工最大的福利!2022新员工入职安全培训全员篇