2828. 判别首字母缩略词

2828. 判别首字母缩略词

解法一: 朴素模拟

go
1
2
3
4
5
6
7
8
9
10
11
func isAcronym(words []string, s string) bool {
if len(words) != len(s) {
return false
}
for i, word := range words {
if word[0] != s[i] {
return false
}
}
return true
}

解法二: java 一行

java
1
2
3
4
5
6
7
class Solution {
public boolean isAcronym(List<String> words, String s) {
return Objects.equals(words.stream()
.map(word -> String.valueOf(word.charAt(0)))
.collect(Collectors.joining()), s);
}
}
作者

wuhunyu

发布于

2023-12-20

更新于

2023-12-20

许可协议