Add solution 0609、0692、0890、1048、1442、1738

This commit is contained in:
YDZ
2021-05-22 19:49:28 +08:00
parent 86370c1ac5
commit 776fe07932
56 changed files with 2894 additions and 1136 deletions

View File

@ -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
}