14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.
题意:
在一个字符串数组中查找最长相同前缀。
思路:
先找到字符串数组中最短的字符串,然后根据这个长度遍历每个string字符串中的字符,只要有一个字符串的字符不相等,则当前找的字符串就是最长相同前缀。
1 | class Solution { |
Java Code:
1 | class Solution { |