-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontest4.cpp
58 lines (54 loc) · 1.27 KB
/
contest4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Weekly Contest 356
//solved 1 out of 4
// 2798. Number of Employees Who Met the Target (accepted)
//tc O(n)
//sc O(1)
//code
class Solution {
public:
int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) {
int count=0;
for(int i=0;i<hours.size();i++){
if(hours[i]>=target){
count++;
}
}
return count;
}
};
//2- 2801. Count Stepping Numbers in Range(not sccepted)
// tle on this code
class Solution {
public:
int strtoint(string s) {
int ans = 0;
for(int i = 0; i < s.size(); i++) {
int temp = s[i] - '0';
ans = ans * 10 + temp;
}
return ans;
}
int countSteppingNumbers(string low, string high) {
int a = strtoint(low);
int b = strtoint(high);
int count = 0;
for(int i = a; i <= b; i++) {
if (i <= 9) {
count++;
} else {
bool isStepping = true;
string numStr = to_string(i);
for (int j = 1; j < numStr.size(); j++) {
if (abs(numStr[j] - numStr[j - 1]) != 1) {
isStepping = false;
break;
}
}
if (isStepping) {
count++;
}
}
}
return count;
}
};