MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / reorderLogFiles

Function reorderLogFiles

reorder_data_in_log_files_937/solution.go:8–30  ·  view source on GitHub ↗
(logs []string)

Source from the content-addressed store, hash-verified

6)
7
8func reorderLogFiles(logs []string) []string {
9 // insertion sort with custom comparison function
10 for i := 1; i < len(logs); i++ {
11 k := i
12 for k > 0 {
13 ct := compareLogs(logs[k-1], logs[k])
14
15 if ct <= 0 {
16 break
17 }
18
19 if ct > 0 {
20 hold := logs[k]
21 logs[k] = logs[k-1]
22 logs[k-1] = hold
23 }
24
25 k--
26 }
27 }
28
29 return logs
30}
31
32func compareLogs(a, b string) int {
33 aTokens := strings.Split(a, " ")

Callers 1

Test_reorderLogFilesFunction · 0.85

Calls 1

compareLogsFunction · 0.85

Tested by 1

Test_reorderLogFilesFunction · 0.68