Hello, welcome to Yizhe's Blog.
I am Yizhe Liu, graduated from University of Arizona, with Master degree, major in Electrical and Computer Engineering. Actually, I am software guy. In my blog, many posts are about the Leetcode questions. I will post my ideas and implementations, which are accepted by Leetcode. If you have different opinions, please leave comment. I am happy to discuss with you. So lets start rocking them!!!
Monday, April 23, 2018
[2018-Interview] Number of 1 Bits
Original question: https://leetcode.com/problems/number-of-1-bits/description/
My answer:
publicclassSolution{// you need to treat n as an unsigned valuepublicinthammingWeight(int n){if(n ==0){return0;}int num1Bit =0;while(n !=0){if((n &1)==1){
num1Bit ++;}
n = n >>>1;}return num1Bit;}}
No comments:
Post a Comment