diff --git a/solved/LeetCode/Challenges/2020/January/27.kt b/solved/LeetCode/Challenges/2020/January/27.kt new file mode 100644 index 00000000..0c0313b9 --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/27.kt @@ -0,0 +1,16 @@ +class Solution { + fun concatenatedBinary(n: Int): Int { + var ans = 0 + val mod = 1000_000_007 + for (i in 1..n) { + val binary = Integer.toBinaryString(i) + for (bit in binary) { + ans = (ans * 2) % mod + if (bit == '1') { + ans = (ans + 1) % mod + } + } + } + return ans + } +}