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
相关推荐
T1an-135 分钟前
力扣70.爬楼梯
算法·leetcode·职场和发展
T1an-137 分钟前
力扣169.多数元素
数据结构·算法·leetcode
我命由我123455 小时前
Photoshop - Photoshop 工具栏(5)多边套索工具
笔记·学习·ui·职场和发展·photoshop·ps·美工
_dindong6 小时前
动规:回文串问题
笔记·学习·算法·leetcode·动态规划·力扣
wangwangmoon_light6 小时前
0.0 编码基础模板
java·数据结构·算法
共享家95276 小时前
Leetcode刷题
算法·leetcode·职场和发展
simon_skywalker6 小时前
第7章 n步时序差分 n步时序差分预测
人工智能·算法·强化学习
山,离天三尺三7 小时前
基于LINUX平台使用C语言实现MQTT协议连接华为云平台(IOT)(网络编程)
linux·c语言·开发语言·网络·物联网·算法·华为云
flashlight_hi7 小时前
LeetCode 分类刷题:74. 搜索二维矩阵
python·算法·leetcode·矩阵
小年糕是糕手7 小时前
【数据结构】算法复杂度
c语言·开发语言·数据结构·学习·算法·leetcode·排序算法