[LeetCode] Check if a String Is an Acronym of Words

2828. Check if a String Is an Acronym of Words

Given an array of strings words and a string s, determine if s is an acronym of words.

The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, "ab" can be formed from ["apple", "banana"], but it can’t be formed from ["bear", "aardvark"].

Return true if s is an acronym of words, and false otherwise.

1
2
3
4
5
6
7
8
class Solution {
public:
bool isAcronym(vector<string>& words, string s) {
string res = "";
for(auto w : words) res.push_back(w[0]);
return res == s;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/08/20/PS/LeetCode/check-if-a-string-is-an-acronym-of-words/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.