close
Given a postive integer, output its complement number. The complemnent strategy is to flip the bits of its binary repressntation.
這也是二進位的問題,要將十進位數字轉換成二進位,然後將01互換後,將新的二進位數字轉成十進位後輸出,也是從accept率高的中挑出來解的題目,因此也沒遇到什麼問題。
進位想法仍然先在紙上用短除法去simulation
while(num>=2){
if(num%2==0) 0
else 1
num/=2
}
在外面再檢驗一次,就完成二進位的轉換。
文章標籤
全站熱搜