Created
July 24, 2018 08:10
-
-
Save luojiyin1987/839b40c44deafcc9d2dacd5afb8acf19 to your computer and use it in GitHub Desktop.
Rotated Digits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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