当前位置:网站首页>2021-06-25: a batch of strings consisting only of lowercase letters (a~z) are put
2021-06-25: a batch of strings consisting only of lowercase letters (a~z) are put
2022-06-24 08:27:00 【Fuda scaffold constructor's daily question】
2021-06-25: Only lowercase letters (a~z) A batch of strings , Are placed in an array of character types String[] arr in , If one of the two strings contains exactly the same type of characters , Just count the two strings as one class , such as :baacbba and bac Even if it is a kind of . return arr How many classes are there in ?
Fuda answer 2021-06-25:
Bit operation . Lowercase letters total 26 individual , integer 32 position , Enough .a To z Corresponding 0 To 26, Traversal string , If it is a, Integer second 0 Change into 1; If it is c, The whole type 2 A into 1. Then save to set in . Multiple strings , Repeat this operation . Finally get set Number of elements of , Is the required return value .
The code to use golang To write . The code is as follows :
package main
import "fmt"
func main() {
arr := []string{"moonfdd", "fddmoon", "aabbcc", "abcde", "abecd"}
ret := types2(arr)
fmt.Println(ret)
}
func types2(arr []string) int {
types := make(map[int]struct{})
for _, str := range arr {
key := 0
for i := 0; i < len(str); i++ {
key |= 1 << (str[i] - 'a')
}
types[key] = struct{}{}
}
return len(types)
}The results are as follows :
边栏推荐
- JVM underlying principle analysis
- ZUCC_编译语言原理与编译_实验04 语言与文法
- jwt(json web token)
- Future trends in automated testing
- Analysis of abnormal problems in domain name resolution in kubernetes
- 疫情下更合适的开发模式
- Synthesize video through ffmpeg according to m3u8 file of video on the network
- Promise的使用场景
- SQL intra statement operation
- Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)
猜你喜欢

一文带你了解Windows操作系统安全,保护自己的电脑不受侵害

Future trends in automated testing

FPGA的虚拟时钟如何使用?

jwt(json web token)

12--合并两个有序链表

Blue Bridge Cup_ Queen n problem

自动化测试的未来趋势

About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe

Installation and use of selenium IDE

Small sample fault diagnosis - attention mechanism code - Implementation of bigru code parsing
随机推荐
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
PAT 1157:校庆
05 Ubuntu installing mysql8
新准则金融资产三分类:AMC、FVOCI和FVTPL
贷款五级分类
2022年流动式起重机司机特种作业证考试题库及在线模拟考试
常用日期格式符与Qt获取当前时间的办法
13 -- 移除无效的括号
js滚动div滚动条到底部
Nodejs redlock notes
Promise的使用场景
MySQL source and target table row count check
487. 最大连续1的个数 II ●●
os. path. Pits encountered during the use of join()
工控机防破解
Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)
Catégorie de prêt 5
transformers PreTrainedTokenizer类
Swift extension chainlayout (UI chain layout) (source code)
Easyplayerpro win configuration full screen mode can not be full screen why