Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created July 24, 2018 08:10
Show Gist options
  • Save luojiyin1987/839b40c44deafcc9d2dacd5afb8acf19 to your computer and use it in GitHub Desktop.
Save luojiyin1987/839b40c44deafcc9d2dacd5afb8acf19 to your computer and use it in GitHub Desktop.
Rotated Digits
func rotatedDigits(N int) int {
count := 0
for i :=2; i <= N; i++ {
if isValid(i) {
count++
}
}
return count
}
func isValid(n int)bool {
var hasValid bool
for n > 0 {
switch n %10 {
case 2, 5, 6, 9:
hasValid = true
case 3, 4,7 :
return false
}
n /= 10
}
return hasValid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment