n
to a string s
.dfs
that takes the current prefix num
, a boolean smaller
indicating if num
is guaranteed to be smaller than s
, and the string s
.num
has the same length as s
, remove leading zeros and check if it is a confusing number after rotation. If it is, return 1, otherwise return 0.ans
to 0 to accumulate the count of confusing numbers.c
:
smaller
is false and c
is greater than the corresponding digit in s
, break the loop.c
to num
.dfs
with the updated num
and smaller
.ans
.num
.ans
.dfs
with an empty string num
, smaller
set to false, and the string s
to start the process.