leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 186191481d9af994dacc615ac52a534f33d8365c
parent 2018fb87bfa7dbb80a368653cd87cb2ee0f881bd
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 25 Nov 2023 22:44:59 +0000

1 Random Problem

Diffstat:
AProblems/0089.cpp | 11+++++++++++
MREADME.md | 1+
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/Problems/0089.cpp b/Problems/0089.cpp @@ -0,0 +1,11 @@ +class Solution { + public: + vector<int> grayCode(const int n) const { + const int k = 1 << n; + vector<int> res(k, 0); + for (int i = 0; i < k; i++) { + res[i] = i ^ (i >> 1); + } + return res; + } +}; diff --git a/README.md b/README.md @@ -107,6 +107,7 @@ for solving problems. | 0086 | Medium | [Partition List](Problems/0086.cpp) | | 0087 | Hard | [Scramble String](Problems/0087.cpp) | | 0088 | Easy | [Merge Sorted Array](Problems/0088.cpp) | +| 0089 | Medium | [Gray Code](Problems/0089.cpp) | | 0090 | Medium | [Subsets II](Problems/0090.cpp) | | 0091 | Medium | [Decode Ways](Problems/0091.cpp) | | 0092 | Medium | [Reverse Linked List II](Problems/0092.cpp) |