Since the problem requires only to check if all tasks can be executed (ie. return type is bool
), the vector<int> sortedOrder
is not necessary. The count can be tracked in a simple int sortedOrder = 0
. Instead of sortedOrder.push_back(vertex)
, you do ++sortedOrder
, and then at the end return sortedOrder == tasks
.
Note: this comment refers to the C++ provided solution.