#=================================== # Tanzila Islam # Email: tanzilamohita@gmail.com # Language: Python 3 #=================================== class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: min_elem = strs[0] for i in range(len(strs)): if len(min_elem) > len(strs[i]): min_elem = strs[i] #print(min_elem) for i in range(len(min_elem)): for j in range(len(strs)): if strs[j][i] != min_elem[i]: return min_elem[:i] return min_elem
Thursday, 20 October 2022
String - 14. Longest Common Prefix
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment