Skip to content

Commit f868e22

Browse files
authored
Create 1056-confusing-number.js
1 parent 79fcc67 commit f868e22

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1056-confusing-number.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number} n
3+
* @return {boolean}
4+
*/
5+
const confusingNumber = function(n) {
6+
// 0, 1, 6, 8, 9
7+
const invalid = new Set(['2', '3', '4', '5', '7'])
8+
const valid = new Set(['6', '9'])
9+
const arr = ('' + n).split('')
10+
let num = 0
11+
for(let i = 0; i < arr.length; i++) {
12+
const ch = arr[i]
13+
if(invalid.has(ch)) return false
14+
if(ch === '6') arr[i] = '9'
15+
else if(ch === '9') arr[i] = '6'
16+
}
17+
arr.reverse()
18+
return arr.join('') !== '' + n
19+
};

0 commit comments

Comments
 (0)