Skip to content

2960. Count Tested Devices After Test Operations 👍

  • Time: $O(n)$
  • Space: $O(1)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution {
 public:
  int countTestedDevices(vector<int>& batteryPercentages) {
    int ans = 0;

    for (const int batteryPercentage : batteryPercentages)
      if (batteryPercentage - ans > 0)
        ++ans;

    return ans;
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution {
  public int countTestedDevices(int[] batteryPercentages) {
    int ans = 0;

    for (final int batteryPercentage : batteryPercentages)
      if (batteryPercentage - ans > 0)
        ++ans;

    return ans;
  }
}
1
2
3
4
5
6
7
8
9
class Solution:
  def countTestedDevices(self, batteryPercentages: list[int]) -> int:
    ans = 0

    for batteryPercentage in batteryPercentages:
      if batteryPercentage - ans > 0:
        ans += 1

    return ans