2023-12-20 LeetCode每日一题(判别首字母缩略词)

2023-12-20每日一题

一、题目编号

复制代码
2828. 判别首字母缩略词

二、题目链接

点击跳转到题目位置

三、题目描述

给你一个字符串数组 words 和一个字符串 s ,请你判断 s 是不是 words 的 首字母缩略词

如果可以按顺序串联 words 中每个字符串的第一个字符形成字符串 s ,则认为 s 是 words 的首字母缩略词。例如,"ab" 可以由 "apple", "banana" 形成,但是无法从 "bear", "aardvark" 形成。

如果 s 是 words 的首字母缩略词,返回 true ;否则,返回 false 。

示例 1:

示例 2:

示例 3:

提示:

  • 1 <= words.length <= 100
  • 1 <= wordsi.length <= 10
  • 1 <= s.length <= 100
  • wordsi 和 s 由小写英文字母组成

四、解题代码

复制代码
class Solution {
public:
    bool isAcronym(vector<string>& words, string s) {
        if (s.size() != words.size()) {
            return false;
        }
        for (int i = 0; i < s.size(); i++) {
            if (words[i][0] != s[i]) {
                return false;
            }
        }
        return true;
    }
};

五、解题思路

(1) 一次遍历判断即可。

相关推荐
mmmmath_31 小时前
LeetCode.541.反转字符串II
数据结构·算法·leetcode
Navigator_Z1 小时前
LeetCode //MySQL - 1251. Average Selling Price
c语言·算法·leetcode
醇氧2 小时前
MySQL 8.0 系统表损坏与引擎转换故障排查实战
数据结构·算法
大熊背2 小时前
《Color constancy by characterization of illumination chromaticity》之色度色域最大化算法(二)
算法·白平衡·色度·色温
钓鱼的肝3 小时前
梳理(1-5)
c++·经验分享·笔记·算法·青少年编程
参.商.3 小时前
【Day 53】76. 最小覆盖子串
leetcode·golang
HZZD_HZZD3 小时前
CSDN_批发市场水电漏损归因算法LAM的原理与落地
嵌入式硬件·物联网·算法
shirsl5 小时前
算法 Day 5 树 / 二叉树 + DFS
数据结构·python·算法
木子算法5 小时前
非凸、离散、还耦合:论文里的求解方法是一条四步流水线
人工智能·算法·目标跟踪