leetcode: Longest Common Prefix

Problem Description:

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

Solution and Precautions:

First sort the array of strings, and just compare each character of the first string and the last string from the start to the end of the shorter string, stop when reaching the end of string or reach a not matched character.

Tips and Divergent thinking:



(转载本站文章请注明作者和出处 烟客旅人 sigmainfy — http://www.sigmainfy.com,请勿用于任何商业用途)

Written on April 21, 2013