classSolution { vector<int> ans; public: voiddfsGoodDaysToRobBank(vector<int>& security, int time, int index){ if (security.size() - index < (time << 1) + 1) { return ; }
int i = index; int sz = time; for (; sz--; i++) { if (security[i] < security[i + 1]) { returndfsGoodDaysToRobBank(security, time, i + 1); } }
int may_ans_index = i; sz = time; for (; sz--; i++) { if (security[i] > security[i + 1]) { // [1,2,5,4,1,0,2,4,5,3,1,2,4,3,2,4,8] 2 // 这个不会输出结果 5 , 只输出 [10, 14], 而不是[5,10,14] // return dfsGoodDaysToRobBank(security, time, i); returndfsGoodDaysToRobBank(security, time, i + 1 - time); } }
ans.push_back(may_ans_index); for (int j = may_ans_index; j <= security.size() - time; j++) { // 前面可知security[j] <= security[j + 1] if (security[j] == security[j + 1]) { if (security[j + time] <= security[j + time + 1]) { ans.push_back(j + 1); } else { returndfsGoodDaysToRobBank(security, time, j + time); } } if (security[j] < security[j + 1]) { returndfsGoodDaysToRobBank(security, time, j + 1); } } }
vector<int> goodDaysToRobBank(vector<int>& security, int time){ ans.clear(); if (time == 0) { for (int i = 0; i < security.size(); i++) { ans.push_back(i); } return ans; }