2828. Check if a String Is an Acronym of Words Easy

@problem@discussion
#Array#String



1/**
2 * [2828] Check if a String Is an Acronym of Words
3 *
4 * Given an array of strings words and a string s, determine if s is an acronym of words.
5 * 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"].
6 * Return true if s is an acronym of words, and false otherwise. 
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: words = ["alice","bob","charlie"], s = "abc"
11 * Output: true
12 * Explanation: The first character in the words "alice", "bob", and "charlie" are 'a', 'b', and 'c', respectively. Hence, s = "abc" is the acronym. 
13 * 
14 * <strong class="example">Example 2:
15 * 
16 * Input: words = ["an","apple"], s = "a"
17 * Output: false
18 * Explanation: The first character in the words "an" and "apple" are 'a' and 'a', respectively. 
19 * The acronym formed by concatenating these characters is "aa". 
20 * Hence, s = "a" is not the acronym.
21 * 
22 * <strong class="example">Example 3:
23 * 
24 * Input: words = ["never","gonna","give","up","on","you"], s = "ngguoy"
25 * Output: true
26 * Explanation: By concatenating the first character of the words in the array, we get the string "ngguoy". 
27 * Hence, s = "ngguoy" is the acronym.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= words.length <= 100
33 * 	1 <= words[i].length <= 10
34 * 	1 <= s.length <= 100
35 * 	words[i] and s consist of lowercase English letters.
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/
41// discuss: https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn is_acronym(words: Vec<String>, s: String) -> bool {
47        false
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_2828() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.