GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode-Swift/String/FindDuplicateFileInSystem.swift at master · iOSRay/LeetCode-Swift

Expand file tree

/

FindDuplicateFileInSystem.swift

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
36 lines (28 loc) · 1.29 KB
/

FindDuplicateFileInSystem.swift

Copy path

File metadata and controls

36 lines (28 loc) · 1.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Question Link: https://leetcode.com/problems/find-duplicate-file-in-system/
* Primary idea: Iterate the paths array and categories paths with the same content
*
* Time Complexity: O(nm), n stands for number of paths, m stands for file number in a path
* Space Complexity: O(n)
*/
class FindDuplicateFileInSystem {
func findDuplicate(_ paths: [String]) -> [[String]] {
var contentToFiles = [String: [String]]()
for path in paths {
let params = path.split(separator: " ")
guard let dir = params.first else {
continue
}
for i in 1..<params.count {
let fileParams = params[i].split(separator: "(")
guard let fileName = fileParams.first, let fileContentWithExtraInfo = fileParams.last else {
continue
}
let fileContent = String(describing: fileContentWithExtraInfo.dropLast())
let filePath = String(describing: dir) + "/" + String(describing: fileName)
contentToFiles[fileContent] = contentToFiles[fileContent, default: []] + [filePath]
}
}
return contentToFiles.values.filter { $0.count >= 2 }
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.