public class Solution {
public List<Integer> grayCode(int n) {
List<Integer> list = new LinkedList<>();
list.add(0);
for (int i = 0; i < n; i++) {
int highbit = 1 << i;
int size = list.size();
for (int j = size - 1; j >= 0; j--) {
int num = list.get(j) + highbit;
list.add(num);
}
}
return list;
}
}
Gray Code
最新推荐文章于 2024-10-06 22:31:44 发布