返回介绍

solution / 2700-2799 / 2798.Number of Employees Who Met the Target / README_EN

发布于 2024-06-17 01:02:59 字数 3572 浏览 0 评论 0 收藏 0

2798. Number of Employees Who Met the Target

中文文档

Description

There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.

The company requires each employee to work for at least target hours.

You are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.

Return _the integer denoting the number of employees who worked at least_ target _hours_.

 

Example 1:

Input: hours = [0,1,2,3,4], target = 2
Output: 3
Explanation: The company wants each employee to work for at least 2 hours.
- Employee 0 worked for 0 hours and didn't meet the target.
- Employee 1 worked for 1 hours and didn't meet the target.
- Employee 2 worked for 2 hours and met the target.
- Employee 3 worked for 3 hours and met the target.
- Employee 4 worked for 4 hours and met the target.
There are 3 employees who met the target.

Example 2:

Input: hours = [5,1,4,2,2], target = 6
Output: 0
Explanation: The company wants each employee to work for at least 6 hours.
There are 0 employees who met the target.

 

Constraints:

  • 1 <= n == hours.length <= 50
  • 0 <= hours[i], target <= 105

Solutions

Solution 1

class Solution:
  def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int:
    return sum(x >= target for x in hours)
class Solution {
  public int numberOfEmployeesWhoMetTarget(int[] hours, int target) {
    int ans = 0;
    for (int x : hours) {
      if (x >= target) {
        ++ans;
      }
    }
    return ans;
  }
}
class Solution {
public:
  int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) {
    int ans = 0;
    for (int x : hours) {
      ans += x >= target;
    }
    return ans;
  }
};
func numberOfEmployeesWhoMetTarget(hours []int, target int) (ans int) {
  for _, x := range hours {
    if x >= target {
      ans++
    }
  }
  return
}
function numberOfEmployeesWhoMetTarget(hours: number[], target: number): number {
  let ans = 0;
  for (const x of hours) {
    if (x >= target) {
      ++ans;
    }
  }
  return ans;
}
impl Solution {
  pub fn number_of_employees_who_met_target(hours: Vec<i32>, target: i32) -> i32 {
    let mut ans = 0;
    for &v in hours.iter() {
      if v >= target {
        ans += 1;
      }
    }
    ans
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文