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

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

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

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

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

# 316. 去除重复字母 真的没看懂,不过很经典

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

给定一个仅包含小写字母的字符串,去除字符串中重复的字母,使得每个字母只出现一次。需保证返回结果的字典序最小(要求不能打乱其他字符的相对位置)。

示例 1:

输入: "bcabc" 输出: "abc" 示例 2:

输入: "cbacdcbc" 输出: "acdb"

# 第一版,用栈写的,改别人的

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

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

string removeDuplicateLetters(string s) {

	unordered_map<char, int> mp;
	unordered_map<char, int> in_st;
	for (int i = 0; i < s.size(); ++i)
		mp[s[i]] = i;//记录某个字符出现的最后位置
	stack<char> st;//记录结果的栈
	for (int i = 0; i < s.size(); ++i) {
		if (in_st[s[i]])
		{
			//cout << "栈中已有元素 " << s[i] << " 个数为 " << in_st[s[i]] << endl;
			continue;//栈中有当前遍历的字符}
		}

		while (st.size() && s[i] < st.top() && mp[st.top()] > i) {
			
			//cout << "循环s[i] " << s[i] << "  st.back()  " << st.top() << "  mp[st.back()]  " << mp[st.top()] << endl;
			//栈顶元素会在之后的位置出现,且要求字典序最小
			--in_st[st.top()];
			//cout << "出栈 " << st.top() << " in_st[s[i]]  " << in_st[st.top()] << endl;
			st.pop();
			//出栈并抹除记录
		}

		st.push(s[i]);
		++in_st[s[i]];
		//cout << "进栈 " << s[i] << " in_st[s[i]] " << in_st[s[i]] << endl;
		//压栈,并记录出现过
	}
	string res;
	/*for (auto& i : st)res += i;*/
	while (!st.empty()) {
		res += st.top();
		st.pop();
	}
	reverse(res.begin(), res.end());
	return res;

}
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

# 第二版,用vector来写,也是原作者的写法

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

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

用栈还是快一些

string removeDuplicateLetters(string s) {

	unordered_map<char, int> mp;
	unordered_map<char, int> in_st;
	for (int i = 0; i < s.size(); ++i)
		mp[s[i]] = i;//记录某个字符出现的最后位置
	vector<char> st;//记录结果的栈
	for (int i = 0; i < s.size(); ++i) {
		if (in_st[s[i]])
		{
			//cout << "栈中已有元素 " << s[i] << " 个数为 " << in_st[s[i]] << endl;
			continue;//栈中有当前遍历的字符}
		}

		while (st.size() && s[i] < st.back() && mp[st.back()] > i) {
			
			//cout << "循环s[i] " << s[i] << "  st.back()  " << st.top() << "  mp[st.back()]  " << mp[st.top()] << endl;
			//栈顶元素会在之后的位置出现,且要求字典序最小
			--in_st[st.back()];
			//cout << "出栈 " << st.top() << " in_st[s[i]]  " << in_st[st.top()] << endl;
			st.pop_back();
			//出栈并抹除记录
		}

		st.push_back(s[i]);
		++in_st[s[i]];
		//cout << "进栈 " << s[i] << " in_st[s[i]] " << in_st[s[i]] << endl;
		//压栈,并记录出现过
	}
	string res;
	for (auto& i : st)
		res += i;

	return res;

}
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