mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-08-02 18:37:22 +08:00
20 lines
383 B
Go
20 lines
383 B
Go
package leetcode
|
|
|
|
func findLongestWord(s string, d []string) string {
|
|
res := ""
|
|
for i := 0; i < len(d); i++ {
|
|
pointS := 0
|
|
pointD := 0
|
|
for pointS < len(s) && pointD < len(d[i]) {
|
|
if s[pointS] == d[i][pointD] {
|
|
pointD++
|
|
}
|
|
pointS++
|
|
}
|
|
if pointD == len(d[i]) && (len(res) < len(d[i]) || (len(res) == len(d[i]) && res > d[i])) {
|
|
res = d[i]
|
|
}
|
|
}
|
|
return res
|
|
}
|