每日一题力扣2960.统计已测试设备c++
2960. 统计已测试设备 - 力扣(LeetCode)
class Solution {
public:
int countTestedDevices(vector<int>& batteryPercentages) {
int count = 0;
for (int i = 0; i < batteryPercentages.size(); i++) {
if (batteryPercentages[i] > 0) {
count++;
for (int j = i + 1; j < batteryPercentages.size(); j++) {
batteryPercentages[j]--;
batteryPercentages[j] = max(0, batteryPercentages[j]);
}
}
}
return count;
}
};