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
相关推荐
MM_MS5 小时前
Halcon变量控制类型、数据类型转换、字符串格式化、元组操作
开发语言·人工智能·深度学习·算法·目标检测·计算机视觉·视觉检测
独自破碎E5 小时前
【二分法】寻找峰值
算法
mit6.8246 小时前
位运算|拆分贪心
算法
ghie90906 小时前
基于MATLAB的TLBO算法优化实现与改进
开发语言·算法·matlab
恋爱绝缘体16 小时前
2020重学C++重构你的C++知识体系
java·开发语言·c++·算法·junit
wuk9986 小时前
VSC优化算法MATLAB实现
开发语言·算法·matlab
Z1Jxxx6 小时前
加密算法加密算法
开发语言·c++·算法
乌萨奇也要立志学C++7 小时前
【洛谷】递归初阶 三道经典递归算法题(汉诺塔 / 占卜 DIY/FBI 树)详解
数据结构·c++·算法
vyuvyucd7 小时前
C++引用:高效编程的别名利器
算法
鱼跃鹰飞7 小时前
Leetcode1891:割绳子
数据结构·算法