Skip to content

Commit 5030c9f

Browse files
authored
Create check-if-number-has-equal-digit-count-and-digit-value.cpp
1 parent 803ab19 commit 5030c9f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// freq table
5+
class Solution {
6+
public:
7+
bool digitCount(string num) {
8+
vector<int> cnt(10);
9+
for (const auto& x : num) {
10+
++cnt[x - '0'];
11+
}
12+
for (int i = 0; i < size(num); ++i) {
13+
if (cnt[i] != num[i] - '0') {
14+
return false;
15+
}
16+
}
17+
return true;
18+
}
19+
};

0 commit comments

Comments
 (0)