Leetcode 練習:2022-01-04

January 04, 2022

Complement of Base 10 Integer

題號:1009

def bitwise_complement(n)
  return 1 if n == 0
  bit = Math::log(n,2).floor + 1
  binary = ("1" * bit).to_i(2)
  binary ^ n
end

Profile picture

Written by Wei Hung who is thinking. You should follow them on Twitter