当前位置:网站首页>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
边栏推荐
- Resizing node of rediscluster cluster cluster mode
- Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
- 股票炒股注册开户靠谱吗?安全吗?
- Redis implements distributed locks
- R language Kolmogorov Smirnov tests whether the two samples follow the same distribution.
- "Three routines" of digital collection market
- 在idea中,get和set方法爆红可能是没有安装Lombok插件
- Kubernetes cluster lossless upgrade practice
- Static resource compression reduces bandwidth pressure and increases access speed
- Recommended system series (Lecture 5): Optimization Practice of sorting model
猜你喜欢

Mysql57 zip file installation

Leetcode learning records

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

PLC -- 笔记

Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)

flex布局

Section VI UART of zynq

在idea中,get和set方法爆红可能是没有安装Lombok插件

HJ质数因子

Unity UI shadow component
随机推荐
Vivo browser rapid development platform practice - Overview
扩展Prometheus的解决方案thanos的简介和几个月使用心得
8 figures | analyze Eureka's first synchronization registry
HJ字符串排序
Sentinel mechanism of redis cluster
mysql57 zip文件安装
A gadget can write crawlers faster
Evolution of vivo push platform architecture
7-1 understand everything
In idea, the get and set methods may be popular because the Lombok plug-in is not installed
R 语言 Hitters 数据分析
自动化测试的生命周期是什么?
Kubernetes理论基础
阿里云服务器创建快照、回滚磁盘
Real time database - Notes
Makefile
以动态规划的方式求解最长回文子串
HJ成绩排序
linux下修改mysql端口号
Install haproxy