Python Concise Code with Explanation

  • 0

    zip - used for iterating over multiple lists.
    *strs - for making multiple lists out of a single list
    Hence, the loop will iterate over 1st character in all the elements then second and so on...

    A set of such a string will have a single character if its a common prefix across all the strings.
    Hence we can break from the loop once this trend ends.

    Hope the explanation helps!

            if not strs:
                return ""
            for letter_group in zip(*strs):
                count = count + 1

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.