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 小时前
F039 python五种算法美食推荐可视化大数据系统vue+flask前后端分离架构
python·算法·vue·推荐算法·美食·五种算法
星空露珠17 小时前
数独解题算法lua脚本
开发语言·数据结构·算法·游戏·lua
小猪咪piggy17 小时前
【算法】day14 链表
数据结构·算法·链表
EnCi Zheng17 小时前
LeetCode_1_两数之和完全解析-从暴力枚举到哈希表优化的算法进阶之路
算法
寂静山林17 小时前
UVa 1620 Lazy Susan
算法
天选之女wow17 小时前
【代码随想录算法训练营——Day51】图论——99.计数孤岛、100.最大岛屿的面积
算法·图论
承渊政道17 小时前
算法复杂度
c语言·数据结构·c++·算法·visual studio
Giser探索家17 小时前
无人机数字资产采集技术架构与实践:从多维度感知到云端化建模的实现路径
大数据·人工智能·算法·计算机视觉·分类·无人机
~~李木子~~17 小时前
动态规划算法实践:从斐波那契到数字推理
算法·动态规划·代理模式
磊-18 小时前
数组双指针总结
数据结构·算法