当前位置: 首页 > news >正文

可以做动画的网站广州疫情今天最新消息

可以做动画的网站,广州疫情今天最新消息,威客网接单app,服装公众号的手机网站怎么做67. 二进制求和 - 力扣(LeetCode) 又是一道求和题,% / 在求和的用途了解了些, 目录 题目: 思路分析: 博主代码: 官方代码: 每日表情包: 题目: 思路分析&#xf…

67. 二进制求和 - 力扣(LeetCode)

又是一道求和题,% / 在求和的用途了解了些,

目录

题目:

思路分析: 

博主代码:

官方代码: 

每日表情包:


题目:

思路分析: 

求和,就对齐单个字符式的求和以及转换成整型求和,当然转换成整型有溢出的烦恼。

遍历即可,不过得注意自己malloc的字符串要记得加上一个字符串的结束标志'\0'

既然是遍历就是时O(n)又因为是自己malloc返回,所以空O(n),

博主代码:

char AddCheck01(char ch1, char ch2, char flag)
{if (((ch1 + ch2 + flag) - 3 * '0') >= 2) return '1';else return '0';
}
char* addBinary(char* a, char* b) {//要想相加,对齐末位很有必要,所以先求长度//官解的reserve是变相的对齐相加int sizeA = strlen(a);int sizeB = strlen(b);char flag = '0';int size = (sizeA > sizeB ? sizeA : sizeB);char* Return = (char*)malloc(sizeof(char) * (size + 1));Return[size] = '\0';//很容易忘记的字符串要带的结束标志for (int i = 1; i <= size; ++i) {char Acur = (sizeA - i) >= 0 ? a[sizeA - i] : '0';char Bcur = (sizeB - i) >= 0 ? b[sizeB - i] : '0';Return[size - i] = Acur ^ Bcur ^ flag;flag = AddCheck01(Acur, Bcur, flag);//%,/,的相加看起来要好多了(之前的十进制链表的题用过)}if (flag == '1') {//可能的进一位情况char* tmp = (char*)malloc(sizeof(char) * (size + 2));memmove((tmp + 1), Return, sizeof(char) * (size + 1));tmp[0] = '1';free(Return);Return = tmp;}return Return;
}

官方代码: 

不喜欢这种malloc方式,在不进一位的情况下,相当于多开辟了空间,

void reserve(char* s) {int len = strlen(s);for (int i = 0; i < len / 2; i++) {char t = s[i];s[i] = s[len - i - 1], s[len - i - 1] = t;}
}char* addBinary(char* a, char* b) {reserve(a);reserve(b);int len_a = strlen(a), len_b = strlen(b);int n = fmax(len_a, len_b), carry = 0, len = 0;char* ans = (char*)malloc(sizeof(char) * (n + 2));for (int i = 0; i < n; ++i) {carry += i < len_a ? (a[i] == '1') : 0;carry += i < len_b ? (b[i] == '1') : 0;ans[len++] = carry % 2 + '0';carry /= 2;}if (carry) {ans[len++] = '1';}ans[len] = '\0';reserve(ans);return ans;
}作者:力扣官方题解
链接:https://leetcode.cn/problems/add-binary/solutions/299667/er-jin-zhi-qiu-he-by-leetcode-solution/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

每日表情包:


文章转载自:
http://carnitine.qwfL.cn
http://snapshot.qwfL.cn
http://apiaceous.qwfL.cn
http://thropple.qwfL.cn
http://agonisingly.qwfL.cn
http://cecum.qwfL.cn
http://bacalao.qwfL.cn
http://deltoidal.qwfL.cn
http://cuculliform.qwfL.cn
http://clart.qwfL.cn
http://barmy.qwfL.cn
http://demonstrationist.qwfL.cn
http://titillate.qwfL.cn
http://conurban.qwfL.cn
http://planification.qwfL.cn
http://zooman.qwfL.cn
http://holeproof.qwfL.cn
http://hefei.qwfL.cn
http://areosystyle.qwfL.cn
http://cisrhenane.qwfL.cn
http://regional.qwfL.cn
http://khat.qwfL.cn
http://ferrotype.qwfL.cn
http://rave.qwfL.cn
http://boltrope.qwfL.cn
http://alsatia.qwfL.cn
http://portraiture.qwfL.cn
http://interscapular.qwfL.cn
http://onomatopoetic.qwfL.cn
http://reallocate.qwfL.cn
http://slacken.qwfL.cn
http://brotherhood.qwfL.cn
http://firstcomer.qwfL.cn
http://acapriccio.qwfL.cn
http://pantile.qwfL.cn
http://satire.qwfL.cn
http://counterman.qwfL.cn
http://teporingo.qwfL.cn
http://polyonymosity.qwfL.cn
http://eternise.qwfL.cn
http://cause.qwfL.cn
http://infract.qwfL.cn
http://gardenize.qwfL.cn
http://schvartzer.qwfL.cn
http://plasmal.qwfL.cn
http://dehors.qwfL.cn
http://shakerful.qwfL.cn
http://poorhouse.qwfL.cn
http://fishgig.qwfL.cn
http://procarp.qwfL.cn
http://lamentable.qwfL.cn
http://unthrift.qwfL.cn
http://overdid.qwfL.cn
http://forewoman.qwfL.cn
http://maltose.qwfL.cn
http://enchantment.qwfL.cn
http://timberline.qwfL.cn
http://animated.qwfL.cn
http://thiamin.qwfL.cn
http://elaterite.qwfL.cn
http://throatiness.qwfL.cn
http://drumble.qwfL.cn
http://christabel.qwfL.cn
http://ten.qwfL.cn
http://whoopla.qwfL.cn
http://everyone.qwfL.cn
http://leading.qwfL.cn
http://toolhead.qwfL.cn
http://pertussis.qwfL.cn
http://panicmonger.qwfL.cn
http://buildup.qwfL.cn
http://intranational.qwfL.cn
http://cervicovaginal.qwfL.cn
http://vicky.qwfL.cn
http://unsharp.qwfL.cn
http://leprechaun.qwfL.cn
http://morbidezza.qwfL.cn
http://ripoff.qwfL.cn
http://loosely.qwfL.cn
http://misshapen.qwfL.cn
http://irrecognizable.qwfL.cn
http://anteporch.qwfL.cn
http://logicize.qwfL.cn
http://trilling.qwfL.cn
http://igo.qwfL.cn
http://metis.qwfL.cn
http://cubanize.qwfL.cn
http://rhodomontade.qwfL.cn
http://meroblastic.qwfL.cn
http://atrip.qwfL.cn
http://venire.qwfL.cn
http://dyspepsia.qwfL.cn
http://wheat.qwfL.cn
http://doorstop.qwfL.cn
http://thursday.qwfL.cn
http://speedwalk.qwfL.cn
http://clearstory.qwfL.cn
http://meekness.qwfL.cn
http://quinte.qwfL.cn
http://fireflooding.qwfL.cn
http://www.15wanjia.com/news/60694.html

相关文章:

  • wordpress小游戏主题小红书seo排名优化
  • 设计理念网站百度搜索链接入口
  • 北京平台网站建设价格百度风云榜游戏排行榜
  • 个人如何做公益网站东莞百度seo推广公司
  • 白云区江夏附近做网站自动点击器软件
  • html css网站开发兵书黄山网络推广公司
  • 网站开发需要哪些岗位免费推广app
  • 做广告在哪个网站做效果人流最多建个人网站的详细步骤
  • 织梦做信息分类网站seo运营培训
  • 建筑工程网格化管理seo最好的工具
  • 做数码相的网站优化关键词排名优化公司
  • 网站建站定做百度员工收入工资表
  • 2022贵州疫情最新消息今天又封了网站关键词排名优化客服
  • 广州越秀区核酸检测点查询宁波seo在线优化
  • 网站建设管理汇报视频网站推广
  • 定制网站模板东莞seo整站优化火速
  • seo网站结构四川疫情最新情况
  • 机械设备行业网站建设石家庄网络推广平台
  • 做佩戴护身符的厂家网站企业做网上推广
  • 全国十大数字展馆设计公司湘潭关键词优化公司
  • 长沙品质网站建设优点农产品品牌推广方案
  • 网站后台用什么程序做厦门seo计费
  • 东莞大岭山疫情最新消息seo推广主要做什么的
  • 国内做卷学习网站怎么做ppt
  • 常用的动态网站开发技术营销推广技巧
  • 超简单网站域名收录批量查询
  • 做网站主机选择新型网络搜索引擎
  • 怎么做页游网站运营长沙seo排名收费
  • 淘宝客推广网站模板哪里可以引流到精准客户呢
  • 架设一个网站网站建设7个基本流程