Skip to content

Instantly share code, notes, and snippets.

@visionbyangelic
Created August 6, 2025 09:05
Show Gist options
  • Select an option

  • Save visionbyangelic/aac7b7efa84a38cd154ba0c29dfac32a to your computer and use it in GitHub Desktop.

Select an option

Save visionbyangelic/aac7b7efa84a38cd154ba0c29dfac32a to your computer and use it in GitHub Desktop.
leetcode-2942-find words containing character

🧠 Approach

Given a list of words and a character x, we need to return the indices of the words that contain that character.

I used a basic loop with enumerate() to track both the index and the word. If the character x is found in the word (if x in word:), I store the index.

βœ… Solution

class Solution:
    def findWordsContaining(self, words: List[str], x: str) -> List[int]:
        result = []
        for i, word in enumerate(words):
            if x in word:
                result.append(i)
        return result

πŸ’¬ Example

words = ["leet", "code"]
x = "e"
# Output: [0, 1] since both "leet" and "code" contain "e"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment