|
| 1 | +# [2798. Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) |
| 2 | + |
| 3 | +[中文文档](/solution/2700-2799/2798.Number%20of%20Employees%20Who%20Met%20the%20Target/README.md) |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +<p>There are <code>n</code> employees in a company, numbered from <code>0</code> to <code>n - 1</code>. Each employee <code>i</code> has worked for <code>hours[i]</code> hours in the company.</p> |
| 8 | + |
| 9 | +<p>The company requires each employee to work for <strong>at least</strong> <code>target</code> hours.</p> |
| 10 | + |
| 11 | +<p>You are given a <strong>0-indexed</strong> array of non-negative integers <code>hours</code> of length <code>n</code> and a non-negative integer <code>target</code>.</p> |
| 12 | + |
| 13 | +<p>Return <em>the integer denoting the number of employees who worked at least</em> <code>target</code> <em>hours</em>.</p> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong class="example">Example 1:</strong></p> |
| 17 | + |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> hours = [0,1,2,3,4], target = 2 |
| 20 | +<strong>Output:</strong> 3 |
| 21 | +<strong>Explanation:</strong> The company wants each employee to work for at least 2 hours. |
| 22 | +- Employee 0 worked for 0 hours and didn't meet the target. |
| 23 | +- Employee 1 worked for 1 hours and didn't meet the target. |
| 24 | +- Employee 2 worked for 2 hours and met the target. |
| 25 | +- Employee 3 worked for 3 hours and met the target. |
| 26 | +- Employee 4 worked for 4 hours and met the target. |
| 27 | +There are 3 employees who met the target. |
| 28 | +</pre> |
| 29 | + |
| 30 | +<p><strong class="example">Example 2:</strong></p> |
| 31 | + |
| 32 | +<pre> |
| 33 | +<strong>Input:</strong> hours = [5,1,4,2,2], target = 6 |
| 34 | +<strong>Output:</strong> 0 |
| 35 | +<strong>Explanation:</strong> The company wants each employee to work for at least 6 hours. |
| 36 | +There are 0 employees who met the target. |
| 37 | +</pre> |
| 38 | + |
| 39 | +<p> </p> |
| 40 | +<p><strong>Constraints:</strong></p> |
| 41 | + |
| 42 | +<ul> |
| 43 | + <li><code>1 <= n == hours.length <= 50</code></li> |
| 44 | + <li><code>0 <= hours[i], target <= 10<sup>5</sup></code></li> |
| 45 | +</ul> |
| 46 | + |
| 47 | +## Solutions |
| 48 | + |
| 49 | +<!-- tabs:start --> |
| 50 | + |
| 51 | +### **Python3** |
| 52 | + |
| 53 | +```python |
| 54 | +class Solution: |
| 55 | + def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int: |
| 56 | + return sum(x >= target for x in hours) |
| 57 | +``` |
| 58 | + |
| 59 | +### **Java** |
| 60 | + |
| 61 | +```java |
| 62 | +class Solution { |
| 63 | + public int numberOfEmployeesWhoMetTarget(int[] hours, int target) { |
| 64 | + int ans = 0; |
| 65 | + for (int x : hours) { |
| 66 | + if (x >= target) { |
| 67 | + ++ans; |
| 68 | + } |
| 69 | + } |
| 70 | + return ans; |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### **C++** |
| 76 | + |
| 77 | +```cpp |
| 78 | +class Solution { |
| 79 | +public: |
| 80 | + int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) { |
| 81 | + int ans = 0; |
| 82 | + for (int x : hours) { |
| 83 | + ans += x >= target; |
| 84 | + } |
| 85 | + return ans; |
| 86 | + } |
| 87 | +}; |
| 88 | +``` |
| 89 | +
|
| 90 | +### **Go** |
| 91 | +
|
| 92 | +```go |
| 93 | +func numberOfEmployeesWhoMetTarget(hours []int, target int) (ans int) { |
| 94 | + for _, x := range hours { |
| 95 | + if x >= target { |
| 96 | + ans++ |
| 97 | + } |
| 98 | + } |
| 99 | + return |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +### **TypeScript** |
| 104 | + |
| 105 | +```ts |
| 106 | +function numberOfEmployeesWhoMetTarget( |
| 107 | + hours: number[], |
| 108 | + target: number, |
| 109 | +): number { |
| 110 | + let ans = 0; |
| 111 | + for (const x of hours) { |
| 112 | + if (x >= target) { |
| 113 | + ++ans; |
| 114 | + } |
| 115 | + } |
| 116 | + return ans; |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +### **...** |
| 121 | + |
| 122 | +``` |
| 123 | +
|
| 124 | +``` |
| 125 | + |
| 126 | +<!-- tabs:end --> |
0 commit comments