public class Solution {
/**
* @param num: the num
* @return: the array subject to the description
*/
public int[] calculateNumber(int num) {
int t, x, y = 0, i;
String s = “”;
x = num;
while (x != 0) {
t = x % 2;
x /= 2;
if (t == 1)
y++;
s = t + s;
}
// System.out.println(s);
int[] r = new int[y + 1];
r[0] = y;
int j=1;
for (i = 0; i < s.length(); i++) {
if (s.charAt(i) == ‘1’)
r[j++] = i + 1;
}
return r;
}http://www.yezidianjing.com/
}
阿里云天池
最新推荐文章于 2024-05-15 21:26:31 发布