mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-23 09:51:45 +08:00
24 lines
584 B
Go
24 lines
584 B
Go
package leetcode
|
|
|
|
import "strings"
|
|
|
|
func findDuplicate(paths []string) [][]string {
|
|
cache := make(map[string][]string)
|
|
for _, path := range paths {
|
|
parts := strings.Split(path, " ")
|
|
dir := parts[0]
|
|
for i := 1; i < len(parts); i++ {
|
|
bracketPosition := strings.IndexByte(parts[i], '(')
|
|
content := parts[i][bracketPosition+1 : len(parts[i])-1]
|
|
cache[content] = append(cache[content], dir+"/"+parts[i][:bracketPosition])
|
|
}
|
|
}
|
|
res := make([][]string, 0, len(cache))
|
|
for _, group := range cache {
|
|
if len(group) >= 2 {
|
|
res = append(res, group)
|
|
}
|
|
}
|
|
return res
|
|
}
|