From e32dd52e3b8d34662401f8a1c23353622138d509 Mon Sep 17 00:00:00 2001 From: GodIsC00L Date: Fri, 17 Jan 2020 19:06:20 +0200 Subject: [PATCH] Added Java solution --- solution/0190.Reverse Bits/Solution.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solution/0190.Reverse Bits/Solution.java diff --git a/solution/0190.Reverse Bits/Solution.java b/solution/0190.Reverse Bits/Solution.java new file mode 100644 index 0000000000000..bcb8afa1cb8ae --- /dev/null +++ b/solution/0190.Reverse Bits/Solution.java @@ -0,0 +1,11 @@ +public class Solution { + // you need treat n as an unsigned value + public int reverseBits(int n) { + int res = 0; + for (int i = 0; i < 31; i++, n>>=1, res<<=1) { + res |= (n&1); + } + res |= (n&1); + return res; + } +} \ No newline at end of file