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
相关推荐
一起努力啊~9 小时前
算法刷题--栈和队列
开发语言·算法
VT.馒头9 小时前
【力扣】2694. 事件发射器
前端·javascript·算法·leetcode·职场和发展·typescript
星火开发设计9 小时前
命名空间 namespace:解决命名冲突的利器
c语言·开发语言·c++·学习·算法·知识
知无不研9 小时前
选择排序算法
数据结构·算法·排序算法·选择排序
好学且牛逼的马9 小时前
【Hot100|21-LeetCode 160. 相交链表】
算法·leetcode
爱学习的阿磊9 小时前
C++中的策略模式应用
开发语言·c++·算法
郝学胜-神的一滴9 小时前
Python中的bisect模块:优雅处理有序序列的艺术
开发语言·数据结构·python·程序人生·算法
筵陌9 小时前
算法:位运算
算法
Remember_9939 小时前
Spring 事务深度解析:实现方式、隔离级别与传播机制全攻略
java·开发语言·数据库·后端·spring·leetcode·oracle
Christo39 小时前
TKDE-2026《Efficient Co-Clustering via Bipartite Graph Factorization》
人工智能·算法·机器学习·数据挖掘