class Solution {
public List<Integer> grayCode(int n) {
List<Integer> result = new ArrayList<>();
result.add(0);
int head = 1;
for (int i = 0; i < n; i++) {
for (int j = result.size() - 1; j >=0; j--) {
result.add(head + result.get(j));
}
head <<= 1;
}
return result;
}
}
leetcode89. 格雷编码
最新推荐文章于 2022-08-24 16:25:31 发布