LeetCode 14. Longest Common Prefix

Description

https://leetcode.com/problems/longest-common-prefix/description/

Write a function to find the longest common prefix string amongst an array of strings.

Explanation

To find the longest common prefix string amongst an array of strings, we can declare a variable “longestCommonPrefix”. In the beginning, it initializes with the value of the first string of the input array. Then compare the “longestCommonPrefix” with all strings in the array to get the longest common prefix for all the strings.

Video Tutorial

Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *