From ee47738d597b332e73456a7c8fc491fc410825c7 Mon Sep 17 00:00:00 2001 From: Manuel Pineda Date: Wed, 27 Jan 2021 20:16:49 +0100 Subject: [PATCH] [LeetCode] Add January 27. --- solved/LeetCode/Challenges/2020/January/27.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 solved/LeetCode/Challenges/2020/January/27.kt 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 + } +}