개발공부/algorithm

[Leetcode][python] 14. Longest Common Prefix

so.py 2021. 7. 4. 21:25

Problem

  • Leetcode 14. Longest Common Prefix
  • Level: Easy
  • Link
 

Longest Common Prefix - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

My Code

class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        strs, temp = sorted(strs),""
        for i in range(len(strs[0])):
            if strs[0][i] == strs[-1][i]: temp += strs[0][i]
            else: break
        return temp