Java easy to understand. 9 lines of simple logic


#1
public class Solution {
    public String longestCommonPrefix(String[] list) {
        
        String prefix = list[0];
        for(int i =1; i<list.length; i++){
            prefix = commonPrefix(prefix, list[i]);
        }
        return prefix;
    }
    
    public String commonPrefix(String s1, String s2){
        int i = 0;
        while(i < s1.length() && i < s2.length() && s1.charAt(i) == s2.charAt(i))
            i++;
        return s1.substring(0,i);
        
    }
}