Skip to content

Commit f4365cc

Browse files
authored
[Array] Add comment for Task Scheduler
1 parent 7906d80 commit f4365cc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Array/TaskScheduler.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Question Link: https://leetcode.com/problems/task-scheduler/
3-
* Primary idea: Most frequent character should be put at head of each chunk and join the chunks with less frequent one.
3+
* Primary idea: Most frequent character should be put at head of each cycle and join the chunks with less frequent one.
44
*
55
* Time Complexity: O(nlogn), Space Complexity: O(n)
66
*
@@ -16,6 +16,7 @@
1616
let sortedTasks = taskFreqs.keys.sorted { return taskFreqs[$0]! > taskFreqs[$1]! }
1717
var mostFreqCount = 0
1818

19+
// get interval number for last cycle
1920
for sortedTask in sortedTasks {
2021
if taskFreqs[sortedTask] != taskFreqs[sortedTasks[0]] {
2122
break
@@ -24,6 +25,8 @@
2425
mostFreqCount += 1
2526
}
2627

28+
// when number of different tasks is greater than n + 1, and the most freqent task won't cause idle run,
29+
// then we should return tasks.count
2730
return max(tasks.count, (taskFreqs[sortedTasks[0]]! - 1) * (n + 1) + mostFreqCount)
2831
}
29-
}
32+
}

0 commit comments

Comments
 (0)