題目描述
因爲golang的int是無限精度的,c++的int是32位的,所以golang的負數相當於前面有無限個1,要對golang的負數做處理.
func NumberOf1( n int ) int { // write code here cnt := 0 if n < 0 { n = n & 0xffffffff } for n != 0 { n = n & (n - 1) cnt++ } return cnt }
因爲golang的int是無限精度的,c++的int是32位的,所以golang的負數相當於前面有無限個1,要對golang的負數做處理.
func NumberOf1( n int ) int { // write code here cnt := 0 if n < 0 { n = n & 0xffffffff } for n != 0 { n = n & (n - 1) cnt++ } return cnt }
shell腳本獲取腳本所在目錄 執行腳本的父目錄不一定是當前的工作目錄。 url=$(dirname $(readlink -f $0))