[LeetCode]Longest Common Prefix
public class Solution { public String longestCommonPrefix(String[] strs) { if (strs.length == 0) { return ""; } int len = 0; while (true) { if (strs[0].length() < len) { return strs[0].substring(0, len - 1); } String prefix = strs[0].substring(0, len); for (String str : strs) { if (str.length() < prefix.length() || !str.startsWith(prefix)) { return str.substring(0, len - 1); } } len ++; } } }