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
相关推荐
2501_9248785914 分钟前
强光干扰下漏检率↓78%!陌讯动态决策算法在智慧交通违停检测的实战优化
大数据·深度学习·算法·目标检测·视觉检测
耳总是一颗苹果1 小时前
排序---插入排序
数据结构·算法·排序算法
YLCHUP1 小时前
【联通分量】题解:P13823 「Diligent-OI R2 C」所谓伊人_连通分量_最短路_01bfs_图论_C++算法竞赛
c语言·数据结构·c++·算法·图论·广度优先·图搜索算法
花火|2 小时前
算法训练营day62 图论⑪ Floyd 算法精讲、A star算法、最短路算法总结篇
算法·图论
GuGu20242 小时前
新手刷题对内存结构与形象理解的冲突困惑
算法
汤永红2 小时前
week4-[二维数组]平面上的点
c++·算法·平面·信睡奥赛
晴空闲雲2 小时前
数据结构与算法-字符串、数组和广义表(String Array List)
数据结构·算法
颜如玉4 小时前
位运算技巧总结
后端·算法·性能优化
冷月半明4 小时前
时间序列篇:Prophet负责优雅,LightGBM负责杀疯
python·算法
秋难降5 小时前
聊聊 “摸鱼式” 遍历 —— 受控遍历的小心机
数据结构·算法·程序员