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
相关推荐
爱编程的鱼21 分钟前
计算机(电脑)是什么?零基础硬件软件详解
java·开发语言·算法·c#·电脑·集合
洛生&28 分钟前
【abc417】E - A Path in A Dictionary
算法
亮亮爱刷题36 分钟前
算法提升之数学(快速幂+逆元求法)
算法
恣艺1 小时前
LeetCode 124:二叉树中的最大路径和
算法·leetcode·职场和发展
1白天的黑夜11 小时前
前缀和-1314.矩阵区域和-力扣(LeetCode)
c++·leetcode·前缀和
weisian1511 小时前
力扣经典算法篇-42-矩阵置零(辅助数组标记法,使用两个标记变量)
算法·leetcode·矩阵
恣艺1 小时前
LeetCode 123:买卖股票的最佳时机 III
算法·leetcode·职场和发展
geoyster2 小时前
20250802-102508010-CP
算法
Q741_1472 小时前
优选算法 力扣 202.快乐数 快慢双指针 解决带环问题 C++解题思路 每日一题
c++·算法·leetcode·快慢双指针·环形问题
DONG9132 小时前
Python 中的可迭代、迭代器与生成器——从协议到实现再到最佳实践
开发语言·汇编·数据结构·python·算法·青少年编程·排序算法