Skip to content

Test Cases for 'Longest Common Prefix' #6285

Open

Description

@mcarr148

Bug Report for https://neetcode.io/problems/longest-common-prefix

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

Probably need another test to confirm one is actually using prefixes - made a mistake in my first submission and this passed:
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
prefix = strs[0]

    for s in strs:
        while prefix and prefix not in s:
            prefix = prefix[:-1]
            if len(prefix) == 0:
                return ""
    
    return prefix

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions