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
相关推荐
why技术24 分钟前
也是出息了,业务代码里面也用上算法了。
java·后端·算法
2501_922895581 小时前
字符函数和字符串函数(下)- 暴力匹配算法
算法
IT信息技术学习圈2 小时前
算法核心知识复习:排序算法对比 + 递归与递推深度解析(根据GESP四级题目总结)
算法·排序算法
愚润求学2 小时前
【动态规划】01背包问题
c++·算法·leetcode·动态规划
会唱歌的小黄李2 小时前
【算法】贪心算法入门
算法·贪心算法
轻语呢喃3 小时前
每日LeetCode : 两数相加--链表操作与进位的经典处理
javascript·算法
钢铁男儿3 小时前
C# 接口(接口可以继承接口)
java·算法·c#
zl_vslam4 小时前
SLAM中的非线性优化-2D图优化之激光SLAM cartographer前端匹配(十七)
前端·人工智能·算法
dying_man5 小时前
LeetCode--44.通配符匹配
算法·leetcode
Paper Clouds5 小时前
代码随想录|图论|15并查集理论基础
数据结构·算法·leetcode·深度优先·图论