[Leet Code] String Matching in an Array

Input: words = ["mass","as","hero","superhero"]
Output: ["as","hero"]
Explanation: "as" is substring of "mass" and "hero" is substring of "superhero".
["hero","as"] is also a valid answer.
Input: words = ["leetcode","et","code"]
Output: ["et","code"]
Explanation: "et", "code" are substring of "leetcode".
Input: words = ["blue","green","bu"]
Output: []
class Solution(object):
def stringMatching(self, words):
"""
:type words: List[str]
:rtype: List[str]
"""
answers = set()
for i in words:
for j in words:
if i != j:
if i in j:
answers.add(i)
return answers

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

DATA STRUCTURES IN PYTHON

An Overview Of The Assembly Language

A warning from a Vim user

Programming at University-Part II: Subject Objectives

Hip-Hip-Array!

My review on online courses for Computer Science — updating everyday…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

All Possible Full Binary Trees Solution | LeetCode-894: Medium | JavaScript Implementation

Iterator Class For Inorder Traversal Of A Binary Tree

[Leet Code] Maximum Number of Words Found in Sentences

What is a Dynamic Array?