• Problem
  • Synced automatically from devbattery/neetcode-submissions

Notes

Write your own notes here. This section is preserved across syncs.

Attempts

Attempt 1 ยท 2026-04-22 ยท Python

class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        answer = ''

        for i in range(len(strs[0])):
            judg = strs[0][i]

            for s in strs:
                if i == len(s) or judg != s[i]:
                    return answer
            
            answer += judg
        
        return answer

Leave a comment