Skip to content

Longest common prefix · ⁨最长公共前缀⁩

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;如果没有公共部分,返回 ""。先用第一个单词作为猜测,然后对照后面每个单词不断缩短,直到它适配所有单词。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩