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
相关推荐
风筝在晴天搁浅1 小时前
代码随想录 718.最长重复子数组
算法
kyle~1 小时前
算法---回溯算法
算法
star _chen1 小时前
C++实现完美洗牌算法
开发语言·c++·算法
hzxxxxxxx1 小时前
1234567
算法
Sylvia-girl2 小时前
数据结构之复杂度
数据结构·算法
CQ_YM2 小时前
数据结构之队列
c语言·数据结构·算法·
VekiSon2 小时前
数据结构与算法——树和哈希表
数据结构·算法
大江东去浪淘尽千古风流人物4 小时前
【DSP】向量化操作的误差来源分析及其经典解决方案
linux·运维·人工智能·算法·vr·dsp开发·mr
Unstoppable224 小时前
代码随想录算法训练营第 56 天 | 拓扑排序精讲、Dijkstra(朴素版)精讲
java·数据结构·算法·
饕餮怪程序猿4 小时前
A*算法(C++实现)
开发语言·c++·算法