MCPcopy Index your code
hub / github.com/TruthHun/BookStack / LongestCommonPrefix

Function LongestCommonPrefix

utils/util.go:1121–1138  ·  view source on GitHub ↗

LongestCommonPrefix 查找最长共同前缀

(strs []string)

Source from the content-addressed store, hash-verified

1119
1120// LongestCommonPrefix 查找最长共同前缀
1121func LongestCommonPrefix(strs []string) string {
1122 if len(strs) == 0 {
1123 return ""
1124 }
1125 if len(strs) == 1 {
1126 return strs[0]
1127 }
1128 mx := 0
1129 for {
1130 for i := 1; i < len(strs); i++ {
1131 if mx >= len(strs[i-1]) || mx >= len(strs[i]) ||
1132 strs[i-1][mx] != strs[i][mx] {
1133 return string(strs[0][:mx])
1134 }
1135 }
1136 mx++
1137 }
1138}

Callers 1

getProjectRootMethod · 0.92

Calls 1

stringFunction · 0.85

Tested by

no test coverage detected