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
相关推荐
im_AMBER3 分钟前
Leetcode 144 位1的个数 | 只出现一次的数字
学习·算法·leetcode
暮冬-  Gentle°7 分钟前
C++中的工厂模式实战
开发语言·c++·算法
Lisssaa8 分钟前
打卡第二十二天
c++·算法·图论
pu_taoc9 分钟前
理解 lock_guard, unique_lock 与 shared_lock 的设计哲学与应用场景
开发语言·c++·算法
小刘不想改BUG12 分钟前
LeetCode 138.随机链表的复制 Java
java·leetcode·链表·hash table
XW010599920 分钟前
6-函数-1 使用函数求特殊a串数列和
数据结构·python·算法
myloveasuka27 分钟前
红黑树、红黑规则、添加节点处理方案
开发语言·算法
沉鱼.4428 分钟前
枚举问题集
java·数据结构·算法
2301_8101609528 分钟前
C++中的访问者模式高级应用
开发语言·c++·算法
郝学胜-神的一滴29 分钟前
走进计算机图形学的浪漫宇宙 | GAMES101 开篇课程全解析
c++·算法·图形渲染·计算机图形学