标签:
public static int[] getCloseNumber(int x){ int[] res = new int[2]; int i = 1; int num = oneNumber(x); while(res[0] == 0 || res[1] == 0){ if(oneNumber(x-i) == num && res[0] == 0){ res[0] = x-i; } if(oneNumber(x+i) == num && res[1] == 0){ res[1] = x + i; } i++; } return res; } public static int oneNumber(int x){ String str = Integer.toBinaryString(x); int res = 0; for(int i = 0; i < str.length();i++){ if(str.charAt(i) == ‘1‘){ res++; } } return res; }
标签:
原文地址:http://www.cnblogs.com/yueyebigdata/p/5085006.html