tantan的博客

Notes, ideas, and observations

无向图给出邻接表, 计算连通分量个数

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
class Solution {
public:
int findCircleNum(vector<vector<int>>& isConnected) {
int len = isConnected.size();
int count = 0;
vector<int>flag(len,0);
for(int i=0;i<len;i++){
if(!flag[i]){
count++;
queue<int>found;
found.push(i);
flag[i]=1;
while(!found.empty()){
int cur = found.front(); found.pop();
for(int j=0;j<len;j++){
if(!flag[j]&&isConnected[cur][j]){
found.push(j);
flag[j]=1;
}
}
}
}
}
return count;
}
};

#关于URL末尾的斜杠

URL末尾有无斜杠会对按相对路径加载的资源造成影响

为什么 ddl 推迟, 开始肝 ddl 的时间也跟着推迟?

#2021 年目标

#学习上

#进步

#装备升级

计网答辩顺利

开心!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char, char>M;
for(int i=0;i<s.size();i++){
char ss = s[i], tt = t[i];
if(M.find(ss)==M.end()){
if(find_if(M.begin(),M.end(),[&](const map<char, char>::iterator&it){return it->second==tt;})!=M.end()){
return false;
}else{
M[ss]=tt;
}
}else{
if(M[ss]!=tt){
return false;
}
}
}
return true;
}
};
0%