Longest common prefix · 最长公共前缀
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Longest common prefix
Return the longest string that starts every word in the array. For flower, flow, flight it's fl; if there's nothing in common, return "". Start with the first word as a guess and shrink it against each next word until it fits them all.
中文
最长公共前缀
返回能作为数组中每个单词开头的最长字符串。对于 flower、flow、flight,答案是 fl;如果没有公共部分,返回 ""。先用第一个单词作为猜测,然后对照后面每个单词不断缩短,直到它适配所有单词。
Complete longestCommonPrefix(String[] strs) returning the longest prefix shared by every string. Return an empty string if there is none or the array is empty. · 完成 longestCommonPrefix(String[] strs),返回所有字符串共有的最长前缀。如果没有公共前缀或数组为空,返回空字符串。
Click Run to see the output here. · 点击“运行”查看此处输出。