聽聞Leetcode的大名,本周也刷了20來題,遇到有一題龜毛題,看似問題很簡單,但要考慮的邊際問題很多。
編號為1834,名稱Single-Threaded CPU。
Input [[19,13],[16,9],[21,10],[32,25],[37,4],[49,24],[2,15],[38,41],[37,34],[33,6],[45,4],[18,18],[46,39],[12,24]]
My Output [6,1,2,9,4,10,0,11,13,5,3,8,12,7]
Leetcode Expected [6,1,2,9,4,10,0,11,5,13,3,8,12,7]
Computed them with my hands and brain.
[[19,13],[16,9],[21,10],[32,25],[37,4],
[49,24],[2,15],[38,41],[37,34],[33,6]
,[45,4],[18,18],[46,39],[12,24]]
T=2, *[2,15]=6
T=17, *[16,9],
[12,24]=1
T=26, [19,13]
,[12,24],*[21,10], [18,18]=2
T=36, [19,13] ,[12,24], [18,18], [32,25], *[33,6]=9
T=42, [19,13] ,[12,24], [18,18], [32,25],*[37,4],[49,24], [38,41],[37,34] =4
T=46, [19,13] ,[12,24], [18,18], [32,25],[49,24], [38,41],[37,34],*
[45,4], [46,39]=10
T=50, *[19,13] ,[12,24], [18,18], [32,25],[49,24],
[38,41],[37,34], [46,39]=1
=11
=13 //don't forget to refer index.
=5
.....略
If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.
留言
張貼留言