LeetCode Longest Common Prefix

2015-01-27 14:16:49 · 作者: · 浏览: 64
Write a function to find the longest common prefix string amongst an array of strings.


这道题目就真的是比较水了,题目意思就是要我们找出最大的公共子序列。通过两个循环就可以解决了!详见代码:

public class Solution {
  	 public String longestCommonPrefix(String[] strs) {
	        String res="";
	        if(strs.length==0)//没输出要输出空字符串
	            return "";
	        int len=strs[0].length();
	        for(int i=1;i
  
   strs[i].length())
	                len=strs[i].length();
	        }
	        for(int i=0;i