kucheasysa

Algoverse_adesh_9

Jun 6th, 2024
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. class Solution:
  2.     def commonChars(self, words: List[str]) -> List[str]:
  3.         a = min(words)
  4.         words.remove(a)
  5.         for char in a[:]: # shallow copy by slice
  6.             for i, word in enumerate(words):
  7.                 if char not in word and (i == len(words) or char in a):
  8.                     a =a.replace(char, "", 1)
  9.                     break
  10.                 else:
  11.                     words[i] = words[i].replace(char, "", 1)
  12.         return a
Advertisement
Add Comment
Please, Sign In to add comment