Skip to content

Commit 5620921

Browse files
authored
Create 1088-confusing-number-ii.js
1 parent 7f2e73e commit 5620921

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

1088-confusing-number-ii.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {number} N
3+
* @return {number}
4+
*/
5+
const confusingNumberII = function (N) {
6+
const valid = [
7+
[0, 0],
8+
[1, 1],
9+
[6, 9],
10+
[8, 8],
11+
[9, 6],
12+
]
13+
function dfs(num, rotated, order) {
14+
let count = 0
15+
if (num !== rotated) count++
16+
for (const [dig, rot] of valid) {
17+
if (num === 0 && dig === 0) continue
18+
if (num * 10 + dig > N) break
19+
count += dfs(num * 10 + dig, rot * order + rotated, order * 10)
20+
}
21+
return count
22+
}
23+
return dfs(0, 0, 1)
24+
}

0 commit comments

Comments
 (0)