葉林
Linked with GitHub
# LeetCode - 0089. Gray Code ### 題目網址:https://leetcode.com/problems/gray-code/ ###### tags: `LeetCode` `Medium` `數學` `位元運算` ```cpp= /* -LeetCode format- Problem: 89. Gray Code Difficulty: Medium by Inversionpeter */ vector <int> answer; class Solution { public: vector<int> grayCode(int n) { int graycode = 0, amount = 1 << n, index = 0; answer.resize(amount); while (index < amount) { answer[index] = graycode; ++index; graycode ^= 1; answer[index] = graycode; ++index; graycode ^= (graycode & (-graycode)) << 1; } return answer; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up