LeetCode刷题(35)--Add Binary
二进制加法:
class Solution(object):def addBinary(self, a, b):""":type a: str:type b: str:rtype: str"""len_a = len(a)len_b = len(b)len_x = max(len_a, len_b)carry = '0'res = ''cnt = 0while len_x > cnt:if cnt >= len_a :i = '0'else :i = a[len_a-1-cnt]if cnt >= len_b :j = '0'else :j = b[len_b-1-cnt]if i == '0' and j == '0':res = carry + rescarry = '0'elif i == '1' and j == '1':res = carry + rescarry = '1'else :if carry == '0':res = '1' + reselse :res = '0' + rescnt += 1if carry == '1':res = '1' + resreturn res
LeetCode刷题(35)--Add Binary相关推荐
- 学渣的刷题之旅 leetcode刷题 35.搜索插入位置(暴力法、二分查找)
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 输入: [1,3,5,6], 5 输出: 2 输 ...
- LeetCode刷题记录4——67. Add Binary(easy)
LeetCode刷题记录4--67. Add Binary(easy) 目录 LeetCode刷题记录4--67. Add Binary(easy) 题目 语言 思路 后记 题目 今天这题是与字符串相 ...
- LeetCode刷题记录14——257. Binary Tree Paths(easy)
LeetCode刷题记录14--257. Binary Tree Paths(easy) 目录 前言 题目 语言 思路 源码 后记 前言 数据结构感觉理论简单,实践起来很困难. 题目 给定一个二叉树, ...
- LeetCode刷题记录6——696. Count Binary Substrings(easy)
LeetCode刷题记录6--696. Count Binary Substrings(easy) 目录 LeetCode刷题记录6--696. Count Binary Substrings(eas ...
- C#LeetCode刷题-字符串
字符串篇 # 题名 刷题 通过率 难度 3 无重复字符的最长子串 24.6% 中等 5 最长回文子串 22.4% 中等 6 Z字形变换 35.8% 中等 8 字符串转整数 (atoi) 15.3% 中 ...
- C#LeetCode刷题-数学
数学篇 # 题名 刷题 通过率 难度 2 两数相加 29.0% 中等 7 反转整数 C#LeetCode刷题之#7-反转整数(Reverse Integer) 28.6% 简单 8 字符串转整数 (a ...
- Leetcode刷题指南和top100题目
原文链接:https://blog.csdn.net/qq_39521554/article/details/79160815 参考博文:https://blog.csdn.net/mmc2015/a ...
- Leetcode刷题
刷题 leetcode 1.两数之和 #哈希表 class Solution:def twoSum(self, nums: List[int], target: int) -> List[int ...
- C#LeetCode刷题-二分查找
二分查找篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30 ...
- LeetCode刷题C++实录
LeetCode刷题C++实录 1. 两数之和 121. 买卖股票的最佳时机 382. 链表随机节点 622. 设计循环队列 623. 在二叉树中增加一行 640. 求解方程 761. 特殊的二进制序 ...
最新文章
- GraphSAGE:我寻思GCN也没我厉害!
- Hive 1.1.1 启动错误
- 【详解!思路清晰】1095 解码PAT准考证 (25分)
- SAP CRM Reference类型下拉菜单里的值是从哪里取出的
- 接入amazon avs_每日新闻综述:亚马逊将互联网接入推向全球的宏伟计划
- set trans 必须是事务处理的第一个语句_MySQL中特别实用的几种SQL语句送给大家
- matlab画线不同颜色_怎样画线框图才有意义?
- WX: picker 滚动选择器
- STL源码剖析 仿函数
- java 内部类序列化_Gson如何序列化内部类
- matlab nntool教程,Matlab nntool 应用实例教材.doc
- linux7inittab文件不存在,Linux下修复inittab文件丢失的两种方法
- webstrom配置一键修复ESLint的报错
- 个人计算机系统的不稳定原因,cpu使用率忽高忽低怎么办 电脑cpu使用率不稳定原因分析【详解】...
- win10 注册表无法删除项
- C# worksheet设置Excel样式(转载)
- 解决CSDN无法上传资源问题
- Linux多人聊天室之前篇
- 机器学习_深度学习毕设题目汇总——交通
- Android实战——jsoup实现网络爬虫,糗事百科项目的起步