leetcode easy - Add Binary

楼主: argorok (s.green)   2022-04-09 22:49:28
Question:
Given two binany strings a and b. return their sum as a binary string.
给两个进位字串a跟b 返回他们的合(也是字串)
Example 1:
Input: a = "11", b = "1"
Output: "100"
Example 2:
Input: a = "1010", b = "1011"
Output: "10101"
Constraints:
- 1 <= a.length, b.length <= 104
- a and b consist only of '0' or '1' characters.
- Each string does not contain leading zeros except for the zero itself.
解法 c++
class Solution {
public:
string addBinary(string a, string b){
int n = a.size();
int m = b.size();
int carry = 0;
string result("");
while(n >=0 || m >=0 || carry){
if(n >= 0) carry += a[n
作者: ILoveElsa (S级18位 梓喵酱油瓶)   2022-04-09 22:51:00
没有res
作者: cpblgu (《超绝望级的cpblgu!》)   2022-04-09 22:52:00
哇靠 你赚真快==
楼主: argorok (s.green)   2022-04-09 22:52:00
靠 这种肺纹还有人看喔菇菇给我500p 让我回本啦 拜托

Links booklink

Contact Us: admin [ a t ] ucptt.com