LeetCode | 89. Gray Code

C++版 - Leetcode 89: Gray Code解题报告 89. Gray Code 提交网址:https://leetcode.com/problems/gray-code/ Total Accepted:58554Total Submissions:161869Difficulty:Medium ACrate:36.2% The gray code is a binary numeral system wh... 阅读详情

The gray code is a binary numeral system where two successive values differ in only one bit.

Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.

For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:

00 - 0
01 - 1
11 - 3
10 - 2

Note:
For a given n, a gray code sequence is not uniquely defined.

For example, [0,2,3,1] is also a valid gray code sequence according to the above definition.

For now, the judge is able to judge based on one instance of gray code sequence. Sorry about that.

Solution

It is easy to understand according to the codes below

Code

//C++
class Solution {
public:
    vector<int> grayCode(int n)
    {
        vector<int> res;
        for(int i=0;i<pow(2.0,n);i++)
        {
            res.push_back(i ^ (i>>1));
        }

        return res;
    }
};
#python
class Solution(object):
    def grayCode(self, n):
        """
        :type n: int
        :rtype: List[int]
        """
        res = []
        Range = pow(2,n)
        for i in range(Range):
            temp = i ^ (i>>1)
            res.append(temp)
        return res
图神经网络与大模型融合的理论综述:架构、机制与未来方向 然而,它们普遍缺乏对图结构数据的原生支持,无法直接处理边、节点之间的拓扑关系,这限制了其在关系密集型任务中的表现 [23]。2020年发布的BERT [16] 开启了自监督预训练时代,而2021年后,T5 [17]、PaLM [18]、LLaMA [19] 等模型相继推出,参数规模突破千亿级,展现出惊人的上下文学习(In-context Learning)与链式推理(Chain-of-Thought)能力 [20]。例如,将医学影像作为图节点,结合病理报告文本,实现更精准的疾病诊断 [58]。 阅读详情

相关推荐

基于AMD AU15P FPGA的SLVS-EC桥PCIe设计方案分享

各位FPGAer周末愉快,今天熊猫君分享一个基于AMD AU15P FPGA的SLVS-EC桥PCIe设计方案。

haoxingheng的专栏 1448

LeetCode --- 89. Gray Code

题目链接:Gray Code The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print th

makuiyu的专栏 3701

新手必看:瑞萨MCU选型时,QFP、QFN、BGA这些封装到底该怎么选?(附选型避坑指南)

本文详细解析了瑞萨MCU选型中QFP、QFN、BGA等封装的特点与适用场景,提供实战避坑指南。通过对比封装的空间占用、散热能力、焊接难度等核心维度,帮助工程师根据具体需求选择最合适的芯片封装,避免因选型不当导致的高成本与生产问题。

weixin_26965807的博客 422

[Leetcode] 89. Gray Code 解题报告

题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the seq

魔豆(Magicbean)的博客 494

Unity资源提取实战指南:工具、工程与效率三维框架

Unity资源提取是游戏维护、外包接手和逆向分析中的基础技术动作,其本质是理解Unity序列化机制与资源加载流程。核心原理在于解析SerializedFile结构、TypeTree类型树及Addressables/AssetBundle双轨架构;技术价值体现在打破加密/压缩/混淆导致的资源不可见性,支撑美术还原、性能优化与项目交接;典型应用场景包括老项目资产抢救、AR仿真数据导出、手游换皮资源复用等。本文聚焦Unity 2019.4+现代管线,深度融合AssetRipper内存注入与三层穿透法,提供可复用的

weixin_30699955的博客 319

linux离线安装nginx

linux离线安装nginx

zhang_130914036的博客 9353

89. Gray Code 题解

89. Gray Code 题目描述: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in

yijingzhi的博客 582

[UE5蓝图基础二]1.[1d混合空间] 走和跑的动画切换(shift切换)

再双击”run”进去 我们需要给他指定一个动画姿势,这里就需要给他我们前面做的”1d”混合空间,然后可以看到”1d” 上有个speed参数,代表的速度 从前面的逻辑来看需要通过控制速度来切换动画,那么必然不能写死速度,把速度提升为变量传递进来即可,所以就得到以下蓝图节点。混合空间的概念:混合空间就是可以将角色多个动画混合在一起 ,我们创建动画类就是创建个”Animation”文件夹 在文件夹内创建混合空间。我们目前要实现的是一个走和跑的功能 那么创建1d即可。到这一步混合空间已经做完 下一步做”动画蓝图”

qq_30584617的博客 3300

leetcode 刷题之路 89 Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of

882

Spring Boot集成Jasypt踩坑实录:自定义SM4加密器Bean加载失败的终极解决方案

本文深入剖析了Spring Boot集成Jasypt时自定义SM4加密器Bean加载失败的根源,即Spring Boot启动流程中Bean加载顺序与Jasypt自动配置的时序冲突。文章提供了三种从源码层面解决问题的有效方案,包括使用ApplicationContextInitializer提前注册、调整Bean依赖顺序以及自定义PropertySource处理机制,并给出了完整的国密SM4加密器实现与测试示例。

weixin_29294975的博客 202

快速入门必看!RT-DETR手把手训练自己的数据集去跑实验,基于 ultralytics 仓库源码改进,配置虚拟环境,准备数据集、训练、验证、推理测试 ,实现0到1的完整教学过程。

本文介绍了使用Ultralytics框架训练RT-DETR模型的全流程。首先需要创建Python 3.10虚拟环境,安装指定版本的PyTorch和相关依赖包。然后准备数据集,修改配置文件,并详细介绍训练、验证和推理三个核心步骤的代码实现。训练阶段使用RTDETR类加载模型配置,设置训练参数;验证阶段评估模型性能;推理阶段可对图片、视频等进行预测。文中还提供了清华大学镜像源加速下载,以及详细的参数配置说明,帮助用户快速搭建RT-DETR目标检测模型。

Ai缝合怪、助力小伙伴高效发论文 5567

LeetCode||89. Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of

Lingfu74的专栏 385

Qt C++ 实现一个完整的扫雷

mineCountLabel = new QLabel(QString("地雷: %1").arg(remainingMines, 3, 10, QChar('0')), this);mineCountLabel->setText(QString("地雷: %1").arg(remainingMines, 3, 10, QChar('0')));timeLabel->setText(QString("时间: %1").arg(gameTime, 3, 10, QChar('0')));" : "游戏失败!

寒寒豆豆软件公司的博客 107

LeetCode89 Gray Code

LeetCode89 Gray Code 问题来源LeetCode89 问题描述 Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.

yanqinghe123的专栏 303

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Leetcode 89 gray code

Leetcode 89 gray code 题目描述 格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异。 给定一个代表编码总位数的非负整数 n,打印其格雷编码序列。格雷编码序列必须以 0 开头。 示例 1: 输入: 2 输出: [0,1,3,2] 解释: 00 - 0 01 - 1 11 - 3 10 - 2 对于给定的 n,其格雷编码序列并不唯一。 例如,[0,2,...

qq_43271202的博客 216

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

LeetCode 89. Gray Code(格雷码生成)

题目来源:https://leetcode.com/problems/gray-code/ 问题描述 89.Gray Code Medium The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integern...

da_kao_la的博客 474

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

leetcode 89 Gray Code

leetcode 89 Gray Code Python C++

快递小可的博客 680

LeetCode89——Gray Code

通过二进制和递归两种方式求解n位生成格雷码(十进制表示)

上善若水 977

Leetcode 89 Gray Code

Gray code 是指一个二进制数字系列,在这样的系列中,两个连续的数字有且只有一个二进制位是不同的。 给出一个非负整数n,代表二进制码的总位数,打印出gray code序列。Gray code的序列以0开始。 例如:给出n = 2,返回[0, 1, 3, 2]。其gray code 序列是: 00 - 0 01 - 1 11 - 3 10 - 2

(ง •̀_•́)ง 604

Leetcode算法学习日志-89 Gray Code

Leetcode 89 Gray Code 题目原文 The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the

Zarlove的博客 434

LeetCode 89: Gray Code 格雷码

The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A

SunliyMonkey 1226

leetcode-89. Gray Code

题目描述(中等难度) 生成 n 位格雷码,所谓格雷码,就是连续的两个数字,只有一个 bit 位不同。 解法一 动态规划 按照动态规划或者说递归的思路去想,也就是解决了小问题,怎么解决大问题。 我们假设我们有了 n = 2 的解,然后考虑怎么得到 n = 3 的解。 n = 2 的解 00 - 0 10 - 2 11 - 3 01 - 1 如果再增加一位,无非是在最高位增加 0 或者 1,考虑先...

猫敷雪 456

LeetCode //C - 89. Gray Code

【代码】LeetCode //C - 89. Gray Code。

Made in Code 810

【leetcode】89. Gray Code【java】

The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of

陈善亮的博客 563

leetcode No89. Gray Code

Question: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the

Dufre 1082

[LeetCode] 89. Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integernrepresenting the total number of bits in the code, print the sequence ...

dey8091的博客 105
上一篇: LeetCode | 81. Search in Rotated Sorted Array II
下一篇: LeetCode | 88. Merge Sorted Array
PKU_CXK
博客等级 码龄10年 87粉丝 142原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值