func rotatedDigits(_ N: Int) -> Int {
var count = 0
for i in stride(from: 1, through: N, by: 1) {
var num = i
var validCount = 0
while num > 1 {
let digit = num % 10
num /= 10
if digit == 0 || digit == 1 || digit == 8 {
continue
}
if digit == 2 || digit == 5 || digit == 6 || digit == 9 {
validCount += 1
} else {
validCount = 0
break
}
}
if validCount > 0 {
count += 1
}
}
return count
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme