Title: Write a function to find the longest common prefix string amongst an array of strings.
Explanation: Ask for the longest identical prefix in an array of input strings
public class Solution {public String longestcommonprefix (string[] strs) {int strslen = strs.length;
String longestcommonprefix = "";
if (Strslen < 1) {return longestcommonprefix;
The position of the shortest string in the string array int minindex = 0;
Shortest string length int minestlen = Strs[0].length ();
for (int i = 1; i < Strslen i++) {int templen = Strs[i].length ();
if (Templen < Minestlen) {Minestlen = Templen;
Minindex = i;
}//Shortest string char[] Minstrchars = Strs[minindex].tochararray ();
The longest same prefix cannot be longer than the shortest string for (int j = 0; J < Minestlen; J + +) {for (int i = 0; i < Strslen; i++) {
char[] Temchars = Strs[i].tochararray ();
if (Temchars[j]!= minstrchars[j]) {return longestcommonprefix; }} LONGESTCOMMONPREfix + = Minstrchars[j];
return longestcommonprefix; }
}