[leetcode ] 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... 阅读详情

class Solution {
public:
    vector<int> grayCode(int n) {
        vector<int> results;
        do{
            if (n < 0)
                break;
            else if (n == 0)
            {
                results.push_back(0);
                break;
            }
            else
            {
                results = grayCode(n-1);
                int length = results.size();
                for (int i = length -1 ; i >=0 ; i--)
                {
                    results.push_back(results[i] + (1<<(n-1)));
                }
            }
        }while(false);
        return results;
        
    }
};



规律总结 : http://xiaotongchen.me/posts/47


注意

results.push_back(results[i] + (1<<(n-1)));

开始结果怎么都是错,后来注意到是运算符优先级的问题!! 注意 + 优先级高于 <<

手把手教你用TiggerRamDisk绕过iPhone/iPad激活锁(支持iOS16.3,Win/Mac双平台保姆级教程) 本文详细介绍了如何使用TiggerRamDisk工具绕过iPhone/iPad的激活锁,支持iOS16.3系统,并提供Windows和Mac双平台的保姆级教程。从工具准备、设备连接到核心解锁流程,一步步指导用户完成操作,帮助二手设备或旧设备重获新生。 阅读详情

相关推荐

海康视觉通讯配置

本文介绍了海康通讯管理中TCP和Modbus协议的配置方法。TCP通讯时,视觉系统作为服务器接收PLC客户端发送的触发信号,需注意十进制与十六进制字符串的转换。Modbus配置需填写PLC的IP地址和寄存器首地址,并预先定义整型变量。TCP通讯需开启16进制发送模式以避免数据格式问题。文章重点说明了不同通讯方式下的数据格式转换和参数设置要点。

A567852的博客 2243

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的博客 215

基于电子海图的水面无人艇全局路径规划

Research and Implementation of Global Path Planning for Unmanned Surface Vehicle Based on Electronic Chart (基于电子海图的水面无人艇全局路径规划)   该论文已经在ICMIR2017会议上发表,附上springer的文献地址 Research and Implementation of Gl...

weixin_30797199的博客 1590

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的专栏 302

VisualStudio2022启动报错

把Users\...\AppData\Local\Microsoft\VisualStudio\11.0\ComponentModelCache中的Microsoft.VisualStudio.Default.cache这个文件移除,再重启vs,各项功能都能正常使用了。第一次使用方法1有效果,不知道什么原因后面又报错再删除缓存文件无效了,最后使用方法2启动VS成功。vs2022启动时,报错弹框,在ActivityLog查看具体报错信息,报错原因未知。网上搜索到两种解决方法。方法1:删除缓存文件。

面朝大海,春暖花开 3938

ComfyUI工作流换脸节点报错ReActorFaceSwap

找到自己ComfyUI安装目录的custom_nodes下是否有这个comfyui-reactor-node-main。大家在借鉴别人工作流进行AI换脸的时候,如果遇到ReActorFaceSwap报错提示,莫慌,看我的,两步解决问题。这里千万注意不要嵌套文件夹,保证点击去这个文件就可以看到内置的配置文件!找到自己ComfyUI安装目录的facerestore_models。如果有这个文件,直接跳过,去下一步。如果没有,可以去Git官网下载。

qq_70810809的博客 9015

Leetcode Gray Code

Leetcode Gray Code,本题主要使用回溯法进行解决,通过一定的规则对二叉树进行遍历,并把值添加入结果集合中,就可以达到目的。要关代友与测试如下:#include<iostream> #include<vector>/** * We used the backtrack method to solve this problem. This problem can be * consi

Ttssxuan 486

接口调试必看:status显示canceled的3种常见原因及修复方法

本文深度解析了接口调试中status显示canceled的三种核心原因:网络层中断(如请求超时)、应用层逻辑主动取消(如请求竞态、组件卸载)以及用户交互与浏览器行为。文章提供了从诊断到修复的系统性方案,包括分析Network Timing、使用Axios CancelToken、优化请求策略与性能,帮助开发者从根本上解决这一常见问题。

bb456的博客 936

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

【蓝牙协议栈】【BLE】详解蓝牙BLE连接建立过程

advertiser。发出广播的设备observer或者scanner。可以扫描广播的设备initiator。能发起连接的设备master或者central。连接成功后的主设备,即主动发起packet的设备slave或者peripheral。连接成功后的从设备,即被动回传packet的设备图11通过时间把observer,initiator和central串起来了,其实这三个角色是相互独立的,也就是说一个设备可以只支持observer角色,而不支持initiator和central角色。

风云说通信 2521

YOLOv11改进策略【卷积层】| ICCV-2023 引入Dynamic Snake Convolution动态蛇形卷积,改进C3k2

基于拓扑几何约束的动态蛇卷积用于管状结构分割DSConv(Dynamic Snake Convolution,动态蛇形卷积)模块的设计主要是为了更好地处理管状结构的分割任务,解决传统卷积在处理细管状结构时的不足。

Limiiiing的博客 1628

[LeetCode]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 se

cjllife的专栏 493

制作INCA和CANape通用的A2L

CANape和INCA通用的A2L配置与修改

赞的博客 5961

LeetCode题目 Gray Code 的解法与疑问

vector grayCode(int n) { vector Bits(1,0); for(int GrayDigit = 0;GrayDigit { int count = Bits.size(); while(count!=0) Bits.push_back(Bits[--count]|(1 /* vector::iterator iter = Bits.end();

catsanddogsman的专栏 731

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Leetcode089 Gray Code(构造)

题目连接:Leetcode089 Gray Code解题思路:假设n-1的序列为a,b,c,d,那么n的序列即为a,b,c,d,d+2^n,c+2^n,b+2^n,a+2^n。class Solution { public: vector&lt;int&gt; grayCode(int n) { vector&lt;int&gt; ans; ans.push_back(0); ...

不慌不忙、不急不躁 218

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LeetCode Gray Code

格雷码表示在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同。现给定二进制码的位数,要求打印出格雷码序列。

DRFish 1147

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Leetcode之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 ...

qq_35455503的博客 173

leetcode笔记:Gray Code(2016腾讯软件开发笔试题)

格雷码是一种数字编码,其中的所有相邻整数在它们的二进制数字表示中只有一个数字不同。现要求打印出二进制比特数是n的所有格雷码。例如,n=2,所有的格雷码是0,1,3,2(对应二进制表示是00,01,11,10)。

liyuefeilong的专栏 3708

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的博客 473

LeetCode: 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 o

Tingmei的专栏 5548

LeetCode——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 cod

白马笑西风的专栏 619

Leetcode: 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

给永远比拿愉快 1417

LeetCode 89. Gray Code (Java版; Medium)

welcome to my blog LeetCode Top Interview Questions 89. Gray Code (Java版; Medium) 题目描述 The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negativ...

littlehaes的博客 233

[Leetcode]Gray_code

问题:产生n位元的所有格雷码。 格雷码(Gray Code)是一个数列集合,每个数使用二进位来表示,假设使用n位元来表示每个数字,任两个数之间只有一个位元值不同。 例如以下为3位元的格雷码: 000 001 011 010 110 111 101 100 。 如果要产生n位元的格雷码,那么格雷码的个数为2^n. 假设原始的值从0开始,格雷码产生的规律是:第一步,改变最右边的

499

Gray Code [leetcode]

第一种方法是直接排列 以二进制为0值的格雷码为第零项,第一项改变最右边的位元,第二项改变右起第一个为1的位元的左边位元,第三、四项方法同第一、二项,如此反复,即可排列出n个位元的格雷码。 vector grayCode(int n) { vector res; res.push_back(0); if (n == 0) return

Peerlessbloom 711
上一篇: Maximum Subarrary
下一篇: Linked List Cycle
benbenab
博客等级 码龄15年 3粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值