Skip to content

Commit c148464

Browse files
authored
Update confusing-number-ii.cpp
1 parent be1da13 commit c148464

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

C++/confusing-number-ii.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,14 @@ class Solution {
104104
class Solution2 {
105105
public:
106106
int confusingNumberII(int n) {
107-
return totalCount(n) - validCountInLessLength(n) - validCountInFullLength(n);
107+
return f(n) - f(0);
108108
}
109109

110110
private:
111+
int f(int n) {
112+
return totalCount(n) - validCountInLessLength(n) - validCountInFullLength(n);
113+
}
114+
111115
int totalCount(int n) { // count all numbers in the pattern of [01689]{1,len(n)} in the range of [0, n]
112116
const auto& s = to_string(n);
113117
int total = 0;

0 commit comments

Comments
 (0)