609.find-duplicate-file-in-system.go 464 B

1234567891011121314151617181920
  1. func findDuplicate(paths []string) [][]string {
  2. res := make([][]string, 0)
  3. m := make(map[string]int)
  4. idx := 0
  5. for _, path := range paths {
  6. strs := strings.Split(path, " ")
  7. for i := 1; i < len(strs); i++ {
  8. names := strings.Split(strs[i], "(")
  9. file := strs[0] + "/" + names[0]
  10. if v, ok := m[names[1]]; ok {
  11. res[v] = append(res[v], file)
  12. } else {
  13. res = append(res, []string{file})
  14. m[names[1]] = idx
  15. idx++
  16. }
  17. }
  18. }
  19. return res
  20. }