mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-25 03:11:41 +08:00
Add solution 0609、0692、0890、1048、1442、1738
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user