[LeetCode]2. Add Two Numbers&67. Add Binary

vSphere环境证书更新/续订案例及注意事项 早期VMware的用户随后“十年之期”已到,陆陆续续出现各种登录问题,证书报错告警等,主要包含6.5到7.0的版本,VMware服务器虚拟化环境涉及的证书及类型较多,在实际更新中会出现各种奇怪的问题,有些坑耗费了大量的troubleshooting时间,极端情况下一天能看到十多遍如下报错😂本文整理了一个近期的更新案例,以及之前处理过的一些问题,仅作参考CA根证书颁发机构,用于签发其他组件的证书,其他证书的有效期不会超过根证书。 阅读详情

2 . Add Two Numbers
Medium
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

49ms:

public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
    int i = 0;
    ListNode p1 = l1, p2 = l2;
    while((p1!=null&&p2!=null)){
        int val = p1.val+p2.val+i;
        i = val / 10;
        p1.val = val % 10;
        p2.val = val % 10;
        if(p1.next==null&&p2.next==null&&i!=0){
            p1.next = new ListNode(1);
            return l1;
        }
        p1 = p1.next;
        p2 = p2.next;
    }
    ListNode notNullNode,res;
    if(p1==null){
        notNullNode = p2;
        res = l2;
    }else{
        notNullNode = p1;
        res = l1;
    }
    while(notNullNode!=null){
        int val = notNullNode.val+i;
        i = val / 10;
        notNullNode.val = val % 10;
        if(notNullNode.next==null&&i!=0){
            notNullNode.next = new ListNode(1);
            i = 0;
        }
        notNullNode = notNullNode.next;
    }    
    return res;
}

67 . Add Binary
Easy
Given two binary strings, return their sum (also a binary string).

For example,
a = “11”
b = “1”
Return “100”.

2ms:

public String addBinary(String a, String b) {
    char[] oper = a.length()>b.length()?a.toCharArray():b.toCharArray();
    char[] add = a.length()>b.length()?b.toCharArray():a.toCharArray();
    int p=0,i=0;
    while(p<add.length){
        int op = oper[oper.length-1-p] - '0';
        int ad = add[add.length-1-p] - '0';
        int val = op + ad + i;
        oper[oper.length-1-p] = (char)((val&1)+'0');
        i = val>>1;
        p++;
    }
    while(i!=0&&p<oper.length){
        int op = oper[oper.length-1-p] - '0';
        int val = op + i;
        oper[oper.length-1-p] = (char)((val&1)+'0');
        i = val >>1;
        p++;
    }
    if(i!=0)
        return "1"+String.valueOf(oper);
    else
        return String.valueOf(oper);
}
华为OD机试 - 统计文本数量(Java 2025 A卷 100分) 华为OD机试 2025A卷题库疯狂收录中,刷题。 阅读详情

相关推荐

Altium Designer20-柔性PCB绘制技巧

Altium Designer2020-柔性PCB绘制技巧 注:教程所用PCB随意找的,并没有完全绘制完,大家学习PCB折弯方法即可。 1.打开PCB,点击视图->板子规划模式1,如下图所示 2.点击设计->定义分割线,用两条分割线绘出要折弯的区域 3.点击设计->定义弯曲线(弯曲线呈现黄色) 4.用快捷键d,k进入layer manage stack(层叠管理器),在f...

weixin_44450279的博客 1万+

LeetCode 2.Add Two Numbers,67.Add Binary,371.Sum of Two Integers,66.Plus One

LeetCode 2.Add Two Numbers, LeetCode 67.Add Binary, LeetCode 371.Sum of Two Integers, LeetCode 66.Plus One

My Blog 862

这可是全网网工数通方向学习路线最完整,最详细的版本,没有之一

文章篇幅较长,耐心看完你一定有所收获。

最铁头的网工博客 2万+

67. Add Binary 二进制加法leetcode

67 Add Binary 二进制加法leetcode题目描述方法1:方法2: 题目描述 Given two binary strings a and b, return their sum as a binary string. 中文:给定两个二进制的字符串,计算他们的加法和,结果以字符串返回 知识点: 1.字符转数字:该字符 - ‘0’ 2.二进制加法 3.进位处理 方法1: 思路:将短字符串前面补零,从后往前对应相加, 二进制加法: 1+1=10,1+1+1=11 十进制加法: 结果有四种情况:0

makeyy123的博客 246

Anomalib实战指南:从零开始构建自定义异常检测数据集

本文提供了一份详细的Anomalib实战指南,指导用户从零开始构建自定义异常检测数据集。文章深入解析了数据准备的核心步骤、目录结构规范,并对比了PatchCore与FastFlow等关键模型的适用场景。通过清晰的代码示例,手把手演示了环境配置、模型训练与推理评估的全流程,旨在帮助开发者快速掌握这一工业视觉异常检测利器,有效解决实际生产中的缺陷识别难题。

weixin_29054245的博客 643

arcgis select by attributes一次选多个_视频:如何基于ArcGIS与GeoDa求莫兰指数和绘制莫兰散点图?...

莫兰指数是全域莫兰指数(Global Moran's I)的简称,是澳大利亚统计学家帕特里克·阿尔弗雷德·皮尔斯·莫兰(Patrick Alfred Pierce Moran),在1950年提出的。详细介绍,如下:莫兰指数取值范围在-1.0至1.0之间。当Moran's I >0时,表示空间正相关性,其值越大,空间相关性越明显;当Moran's I <0时,表示空间负相关性...

weixin_39948247的博客 1759

Leetcode日练笔记24 #67 #28 Add Binary & Implement strStr()

#67 Add Binary Given two binary stringsaandb, returntheir sum as a binary string. 解题思路: 1. 考虑到 string A B 的长度可能不一样所以先补齐零。 2. 然后将string A和B 同一个index的数字求和之后赋予给新的string,new 3. 用for循环去从后往前看new每一个数位是不是大于2。逢二进一。 4.将new转变为string输出。 class Solution: ...

Bittersweet_t的博客 252

集群路径规划实战(一)之EGO-swarm环境搭建与调试

本文详细介绍了EGO-swarm分布式无人机集群运动规划系统的仿真环境搭建与调试全流程。内容涵盖ROS Melodic安装、代码获取、依赖库配置、编译问题解决(如multi_map_server头文件缺失)以及最终通过roslaunch启动集群仿真与Rviz可视化,为学习和研究集群路径规划算法提供了可运行的实战平台。

weixin_29243279的博客 250

[LeetCode] Add Binary

https://leetcode.com/problems/add-binary/ 模拟加法操作,链表也有类似的问题(Add Two Numbers)。 /* * author : TK * date : 2017-02-14 * problem: LeetCode 67: Add Binary * method : simulate the operation of add...

Sari_2015的博客 154

【电机应用控制】——步进电机控制原理(四相五线/两相四线/细分驱动)&驱动器&梯形/S形加减速算法&直线/圆弧插补

步进电机是一种把电脉冲信号转换为角位移(左)或线位移(右)的电动机。两相通常1.8°,三相通常1.2°、无相通常0.72°,角位移=脉冲个数X步距角。在非超载且不超频的情况下,电机的旋转位置只取决于脉冲个数,转速只取决脉冲信号的频率。所以只需要统计脉冲个数和频率,不再需要编码器测速和位置,具有优秀的开环能力,当然也可接编码器反馈速度和位置数据,实现更加精准的闭环控制。永磁式动态性能好,输出力矩大,但步距角大通常7.5°;反应式(磁阻式)结构简单成本低,步距角小一般1.2°,但振动噪音大动态性能差;

weixin_51658186的博客 5万+

ABAP CDS View 从入门到精通教程第一篇:ABAP CDS View 在 SAP 技术体系中的重要地位

摘要:本文介绍了SAP开发技术专家提供的多套SAP开发教程,涵盖ABAP、UI5、Fiori、OData、BTP等技术领域。重点阐述了ABAP CDS View在SAP S/4HANA中的核心地位,作为虚拟数据模型(VDM)的关键技术,它实现了OLTP和OLAP的统一处理。文章还说明了学习CDS View的前置条件,包括需要SAP NetWeaver 7.50 SP01或更高版本系统,以及使用SAP ABAP Development Tool进行开发实践。作者具有16年SAP开发经验,这些教程形成了完整的S

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 897

LeetCode C++ 67. Add Binary【String】简单

Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0 . Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" Const

memcpy0的博客 750

【Segment Anything Model】十(1):利用SAM做分类任务,方法二,不放过SAM强大特征提取能力,将SAM提取到的ImageEmbedding插入到其他cnn网络中

直接黏贴复制就好'''该类定义了VGG-16的基本结构。features: 代表VGG网络的主体部分,即所有的卷积层和池化层。avgpool: 是自适应平均池化层,将特征图大小调整为7x7。classifier: 是VGG网络的分类部分,由全连接层组成。_initialize_weights(): 初始化权重的方法。

cvxiayixiao的博客 3561

【leetcode c++】67 Add Binary

Add Binary Given two binary strings, return their sum(also a binary string).   For example, a = "11" b = "1" Return "100".             二进制大家都知道,这题要求我们给定两个string形式的二进制数字,要我们做加法并返回一个string。 有看

lif的博客 751

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Add Binary -- LeetCode

原题链接: http://oj.leetcode.com/problems/add-binary/  这道题跟Add Two Numbers很类似,代码结构很接近。从低位开始,一直相加并且维护进位。和Add Two Numbers的区别是这个题目低位在后面,所以要从string的尾部往前加。时间复杂度是O(m+n),m和n分别是两个字符串的长度,空间复杂度是结果的长度O(max(m,n)

Code Ganker 1万+

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Leetcode 67 Add Binary

Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 模拟二进制加法,先逆置字符串,补全短串的前导0,最后注意首位进位! class Solution { public: string addBinary(s

无名山丘,崛起成峰 1443

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Add Two Numbers -- LeetCode

原题链接: http://oj.leetcode.com/problems/add-two-numbers/  这道题比较简单,是cc150里面的题,思路很明确,就是按照位数读下去,维护当前位和进位,时间复杂度是O(n),空间复杂度是O(1).代码如下:  public ListNode addTwoNumbers(ListNode l1, ListNode l2) { int car

Code Ganker 1万+

leetcode python3 简单题67. Add Binary

1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第六十七题 (1)题目 英文: Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only char...

从此做一个俗人 351

[LeetCode] Add Two Numbers、Divide Two Integers、Multiply Strings、Add Binary、Plus One

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

a83610312的专栏 1106

67. Add Binary

67. Add Binary 题目描述:Given two binary strings, return their sum (also a binary string).For example, a = "11" b = "1" Return "100". 题目大意:进行二进制加减 思路:直接运用二进制加减规则进行加减即可 代码package String;/** * @Author Oov

OovEver的专栏 278

leetcode——67——Add Binary

Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". class Solution { public: string addBinary(string a, string b) { int

happyxuma1991的博客 295

leetcode最优解整理(dfs/String/Binary Search/Two pointers/Math/Dynamic programming)

从今天开始将自己做过的leetcode进行整理,争取做到bug-free~ recursive 1. Two Sum 根据target求两数在数组中的index  思路:用HashMap(时间复杂度o(n)) 方法2:敏感关键字array和target,想到二分查找法(但需要一点一点挪low和high指针)。  排序后,target == numbers[low]+numb

hulamua的博客 1984

【Leetcode】67. Add Binary

Given two binary strings, return their sum (also a binary string). The input strings are bothnon-emptyand contains only characters1or0. Example 1: Input: a = "11", b = "1" Output: "100" Exam...

小I的博客 125

LeetCode *** 67. Add Binary

题目: Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 分析: 一个一个加即可。。。话说我困到die。。。还有12道题。。 代码: class Solution { public: stri

treeshy的博客 248

LeetCode67——Add Binary

Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 难度系数: 容易 实现 string addBinary(string a, string b) { string sum; int

代码菌的blog 1126

Leetcode 67 Add Binary 二进制加

题目描述:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".用两个string表示大数,返回他们的和(也用string)思路:    1.不用想,这道题用string肯定是有坑的,很有可能输入的string很长,远远超过了long lon...

yuweiming70的博客 170
上一篇: [LeetCode]15. 3Sum【&16. 3Sum Closest】
下一篇: [Leetcode]160.Intersection of Two Linked Lists
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值