1.tcp上面可以有多少个http协议连接
结束后查找的答案。
默认情况下建立 TCP 连接不会断开,只有在请求报头中声明 Connection: close 才会在请求完成后关闭连接。
如果维持连接,一个 TCP 连接是可以发送多个 HTTP 请求的。
推荐:https://zhuanlan.zhihu.com/p/61423830
2.数据库查询
假设有关注表follows,表结构如下,我现在想查出关注用户10和20的人的id
CREATE TABLE `follow` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `follower` int(11) DEFAULT NULL COMMENT '关注人', 粉丝 `followed` int(11) DEFAULT NULL COMMENT '被关注的人', 网红 PRIMARY KEY (`id`) ) ENGINE=InnoDB 解: select * from (select * from follow where followed=10) a inner join (select * from follow where followed=20) b on a.follower=b.follower;
3.
给你一个字符串 s,「k 倍重复项删除操作」将会从 s 中选择 k 个相邻且相等的字母,并删除它们,使被删去的字符串的左侧和右侧连在一起。
你需要对 s 重复进行无限次这样的删除操作,直到无法继续为止。
在执行完所有删除操作后,返回最终得到的字符串。
本题答案保证唯一。
示例 1:
输入:s = "abcd", k = 2 输出:"abcd" 解释:没有要删除的内容。
示例 2:
输入:s = "deeedbbcccbdaa", k = 3 输出:"aa" 解释: 先删除 "eee" 和 "ccc",得到 "ddbbbdaa"
再删除 "bbb",得到 "dddaa"
最后删除 "ddd",得到 "aa"
示例 3:
输入:s = "pbbcggttciiippooaais", k = 2 输出:"ps"
#include <iostream> using namespace std; char s[100000]; struct node{ char c; int num; } int main() { int k; int len=strlen(s); stack<char> sta; vector<char> ans; for(int i=0;i<len;i++){ if(sta.empty()){ sta.push(node(s[i],1)); }else{ if(sta.top().c==s[i]&&sta.top().num+1<k){ sta.push(node(s[i],sta.front().num+1)); }else if(sta.top().c!=s[i]){ sta.push(node(s[i],1)); }else if(sta.top().c==s[i]&&sta.front().num+1==k){ int temp=k-1; while(k){ sta.pop(); temp--; } } } while(!sta.empty()){ ans.push_back(sta.top()); sta.pop(); } } }