lcp356

第一题 满足目标工作时长的员工数目

方法一:模拟

1
2
3
4
5
6
7
8
9
class Solution {
public int numberOfEmployeesWhoMetTarget(int[] hours, int target) {
int res = 0;
for (int x : hours)
if (x >= target)
++res;
return res;
}
}

第二题统计完全子数组的数目

方法一:HashSet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public int countCompleteSubarrays(int[] nums) {
Set<Integer> set = new HashSet<>();
for (int x : nums)
set.add(x);
int length = set.size(), res = 0, n = nums.length;
// 以第i位结尾,有多少完全子数组,i >= length
for (int i = length - 1; i < n; ++i) {
Set s = new HashSet();
for (int j = i; j >= 0; --j) {
s.add(nums[j]);
if (s.size() == length) {
++res;
}
}
}
return res;
}
}

第三题包含三个字符串的最短字符串

方法一:

1

第四题

方法一:

1

2719. 统计整数数目

2376. 统计特殊整数


lcp356
https://leopol1d.github.io/2023/07/30/lcp356/
作者
Leopold
发布于
2023年7月30日
许可协议