标签:desc code 举例 输入 style solution 表示 tle title
public class Solution { public int NumberOf1(int n) { int count=0; while(n!=0){ count++; n=n&(n-1); } return count; } }
举例:
1100
1100-1=1011
1100&1011=1000,count+1
有多少个1,就能&多少次(相同为1)
标签:desc code 举例 输入 style solution 表示 tle title
原文地址:https://www.cnblogs.com/chanaichao/p/10121769.html