Last active
May 27, 2020 03:08
-
-
Save marklin-latte/371ea3109a1d835488578635a3c4c0ef to your computer and use it in GitHub Desktop.
This file contains 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
function g(n){ | |
let res = 0; | |
for (let i=1; i <= n; i++){ | |
let temp = i; | |
while(temp != 0){ | |
let digit = temp % 10; | |
if(digit == 7){ | |
res++; | |
break; | |
} | |
temp = Math.floor(temp / 10); | |
} | |
} | |
return res; | |
} | |
g(70); // 8 | |
g(100); // 19 (1*9 + 10) = 19 | |
g(1000); // 271 (19*9 + 100) = 271 | |
g(10000); // 3439 (271*9 + 1000) = 3439 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment