fork download
  1. # your code goes here
  2. class Solution:
  3. def commonChars(self, words: list[str]) -> list[str]:
  4. # Start with the characters of the first word
  5. common = list(words[0])
  6.  
  7. # Filter characters against each subsequent word
  8. for word in words[1:]:
  9. next_common = []
  10. for char in common:
  11. if char in word:
  12. next_common.append(char)
  13. # Remove the letter so it isn't matched again for this word
  14. word = word.replace(char, "", 1)
  15. common = next_common
  16.  
  17. return common
  18.  
Success #stdin #stdout 0.07s 13984KB
stdin
Standard input is empty
stdout
Standard output is empty