Leetcode 2942. Find Words Containing Character

Problem

You are given a 0-indexed array of strings words and a character x.

Return an array of indices representing the words that contain the character x.

Note that the returned array may be in any order.

Algorithm

Just enumerate and check directly.

Code

python3 复制代码
class Solution:
    def findWordsContaining(self, words: List[str], x: str) -> List[int]:
        ans = []
        for i, word in enumerate(words):
            if x in word:
                ans.append(i)
        
        return ans
相关推荐
要努力啊啊啊17 分钟前
BPE、WordPiece 与 Unigram:三种主流子词分词算法对比
算法
君鼎41 分钟前
剑指offer11_矩阵中的路径
数据结构·c++·算法
苏荷水1 小时前
day11 leetcode-hot100-18(矩阵1)
算法·leetcode·矩阵
wen__xvn2 小时前
DFS:从入门到进阶的刷题指南
算法·深度优先
xiaohanbao092 小时前
day40 python图像数据与显存
python·深度学习·学习·算法·机器学习·图像
wen__xvn2 小时前
每日刷题c++
数据结构·c++·算法
橙留香mostarrain2 小时前
从零开始的数据结构教程(六) 贪心算法
数据结构·算法·贪心算法
点云SLAM2 小时前
PyTorch中 torch.utils.data.DataLoader 的详细解析和读取点云数据示例
人工智能·pytorch·python·算法·计算机视觉·dataloader·3d深度学习
思绪漂移3 小时前
同源“平滑思想”的问题解法:正则化与拉普拉斯平滑
人工智能·算法
想睡hhh3 小时前
Practice 2025.5.29 —— 二叉树进阶面试题(1)
c++·算法