Skip to content

Commit af8364c

Browse files
add 89
1 parent 09e5f3e commit af8364c

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ LeetCode
8282
|0083|[Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) | c | [c++](./src/0083-Remove-Duplicates-from-Sorted-List/0083.cpp) |[python](./src/0083-Remove-Duplicates-from-Sorted-List/0083.py)|||Easy|
8383
|0086|[Partition List](https://leetcode.com/problems/partition-list/) | c | [c++](./src/0086-Partition-List/0086.cpp) |[python](./src/0086-Partition-List/0086.py)|||Medium|
8484
|0088|[Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/) | c | [c++](./src/0088-Merge-Sorted-Array/0088.cpp) |[python](./src/0088-Merge-Sorted-Array/0088.py)|||Easy|
85+
|0089|[Gray Code](https://leetcode.com/problems/gray-code/) | c | [c++](./src/0089-Gray-Code/0089.cpp) |[python](./src/0089-Gray-Code/0089.py)|||Medium|
8586
|0090|[Subsets II](https://leetcode.com/problems/subsets-ii/) | c | [c++](./src/0090-Subsets-II/0090.cpp) |[python](./src/0090-Subsets-II/0090.py)|||Medium|
8687
|0091|[Decode Ways](https://leetcode.com/problems/decode-ways/) | c | [c++](./src/0091-Decode-Ways/0091.cpp) |[python](./src/0091-Decode-Ways/0091.py)|||Medium|
8788
|0092|[Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) | c | [c++](./src/0092-Reverse-Linked-List-II/0092.cpp) |[python](./src/0092-Reverse-Linked-List-II/0092.py)|||Medium|

src/0089-Gray-Code/0089.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
2+
class Solution
3+
{
4+
public:
5+
vector<int> grayCode(int n)
6+
{
7+
if (n == 0) return {0};
8+
vector<int> res;
9+
for (int i = 0; i < 1<<n; ++i)
10+
{
11+
res.push_back(i^i>>1);
12+
}
13+
return res;
14+
}
15+
};

src/0089-Gray-Code/0089.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def grayCode(self, n):
3+
"""
4+
:type n: int
5+
:rtype: List[int]
6+
"""
7+
if n == 0:
8+
return [0]
9+
10+
res = list()
11+
for i in range(1 << n):
12+
res.append(i ^ (i>>1))
13+
return res

0 commit comments

Comments
 (0)