LC.P2828[判别首字母缩略词]

方法一:模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public boolean isAcronym(List<String> words, String s) {
if (words.size() != s.length()) {
return false;
}
for (int i = 0; i < s.length(); ++i) {
if (words.get(i).charAt(0) != s.charAt(i)) {
return false;
}
}
return true;
}
}
  • 时间复杂度:$O(n)$,$n$为$words$的长度
  • 空间复杂度:$O(1)$