这是四则或许对你有些许帮助的信息:

1、👉 最近我发现了一个每日都会推送最新校招资讯的《校招日程》文档,其中包括往届补录应届实习校招信息,比如各种大厂、国企、银行、事业编等信息都会定期更新,帮忙扩散一下。

2、😍 免费分享阿秀个人学习计算机以来收集到的免费学习资源,点此白嫖;也记录一下自己以前买过的不错的计算机书籍、网络专栏和垃圾付费专栏

3、🚀如果你想在校招中顺利拿到更好的offer,阿秀建议你多看看前人踩过的坑留下的经验,事实上你现在遇到的大多数问题你的学长学姐师兄师姐基本都已经遇到过了。

4、🔥 欢迎准备计算机校招的小伙伴加入我的学习圈子,一个人踽踽独行不如一群人报团取暖,圈子里沉淀了很多过去21/22/23届学长学姐的经验和总结,好好跟着走下去的,最后基本都可以拿到不错的offer!此外,每周都会进行精华总结和分享!如果你需要《阿秀的学习笔记》网站中📚︎校招八股文相关知识点的PDF版本的话,可以点此下载

# 67. 二进制求和

力扣原题链接(点我直达) (opens new window)

给定两个二进制字符串,返回他们的和(用二进制表示)。

输入为非空字符串且只包含数字 10

示例 1:

输入: a = "11", b = "1"
输出: "100"
1
2

示例 2:

输入: a = "1010", b = "1011"
输出: "10101"
1
2

# 第一版,其实不难,仔细一点就可以了

执行用时 :8 ms, 在所有 cpp 提交中击败了48.84%的用户

内存消耗 :8.7 MB, 在所有 cpp 提交中击败了45.19%的用户

    string addBinary(string a, string b) {
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (a.size() < b.size()) swap(a, b);

	vector<char> res;
	int len = b.size(),minus = a.size()-b.size();
	for (int i = 0; i <len; ++i) {
		res.push_back(b[i] - '0' + a[i]);
	}
	//cout << res << endl;
	for (int i = len; i < len+minus; ++i)
		res.push_back(a[i]);
	/*reverse(res.begin(), res.end());
	cout << res << endl;*/
	//for (auto a : res)
	//	cout << a;
	//cout << endl;
	for (int i = 0; i <len+minus-1; ++i) {
		if (res[i] >= '2') {
			res[i + 1] = res[i + 1] + (res[i] - '0')/2;
			res[i] = '0' + (res[i] -'0') % 2;
		}

		//for (auto a : res)
		//	cout << a;
		//cout << endl;
	}
	//cout << res << endl;
	string result;
	for (auto& a : res)
		result += a;

	//cout << result << endl;

	reverse(result.begin(), result.end());
	if (result[0] > '1') {
		result[0] = result[0] -2;
		result = '1' + result;
	}

	//cout << res << endl;
	//while (res[0] > '1') {
	//	res[0] = res[0] - 2;
	//	res = '1' + res;
	//}
	//reverse(res.begin(), res.end());
	return result;
        
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50