LeetCode2828. 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.

Example 1:

Input: words = "alice","bob","charlie", s = "abc"

Output: true

Explanation: The first character in the words "alice", "bob", and "charlie" are 'a', 'b', and 'c', respectively. Hence, s = "abc" is the acronym.

Example 2:

Input: words = "an","apple", s = "a"

Output: false

Explanation: The first character in the words "an" and "apple" are 'a' and 'a', respectively.

The acronym formed by concatenating these characters is "aa".

Hence, s = "a" is not the acronym.

Example 3:

Input: words = "never","gonna","give","up","on","you", s = "ngguoy"

Output: true

Explanation: By concatenating the first character of the words in the array, we get the string "ngguoy".

Hence, s = "ngguoy" is the acronym.

Constraints:

1 <= words.length <= 100

1 <= wordsi.length <= 10

1 <= s.length <= 100

wordsi and s consist of lowercase English letters.

二、题解

cpp 复制代码
class Solution {
public:
    bool isAcronym(vector<string>& words, string s) {
        string s1 = "";
        for(auto word:words){
            s1 += word[0];
        }
        return s1 == s;
    }
};
相关推荐
皓月斯语11 分钟前
B3867 [GESP202309 三级] 小杨的储蓄 题解
c++·算法·题解
mifengxing29 分钟前
Java 集合进阶(一)
java·开发语言·数据结构·复习笔记
半夢半醒134 分钟前
[原创]《C#高级GDI+实战:从零开发一个流程图》第章:增加菱形、平行四边形、圆角矩形,文本居中显示
算法·c#·流程图
choumin35 分钟前
行为型模式——模板方法模式
c++·设计模式·模板方法模式·行为型模式
Jerry43 分钟前
LeetCode 90. 子集 II
算法
机器学习之心1 小时前
CCD实验设计+SVM代理建模+改进NSGA-II工艺参数多目标优化,MATLAB代码
算法·支持向量机·matlab·多目标优化
SOLECA_1 小时前
Ascend C 算子实战(二)|SigmoidCustom 逐元素激活算子完整开发指南
算法
Jerry1 小时前
LeetCode 78. 子集
算法
DuHz2 小时前
论文解读:用于数据分析的极值点对称模态分解方法 (Extreme-point Symmetric Mode Decomposition,ESMD)
论文阅读·算法·信息与通信·信号处理