tantan的博客

Notes, ideas, and observations

2021年目标

#学习上

iOS答辩

数据仓库答辩

计网答辩顺利

开心!

su user 和 su - user的区别

$ su user启动nologin shell

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;
}
};

配环境心得

放平心态

给出n个集合和k次查询, 计算集合相似度:

集合相似度 = 交集元素数量 / 并集元素数量

指针

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
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
ListNode*p1=l1,*p2=l2,*p3,*last=nullptr;
int up=0;
ListNode* root=new ListNode();
p3=root;
while(p1 || p2 || up){
int n1=0,n2=0;
if(p1){n1=p1->val;p1=p1->next;}
if(p2){n2=p2->val;p2=p2->next;}
up+=n1+n2;
p3->val=up%10;
last=p3;
p3=p3->next=new ListNode();
up/=10;
}
delete last->next;
last->next=nullptr;
return root;
}
};

排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(),g.end()); // 1 2 3
sort(s.begin(),s.end()); // 1 1
int count=0;
for(int i=s.size()-1, gg=g.size()-1;i>=0&&gg>=0;i--,gg--,count++){
int ss=s[i];
while(gg>=0&&g[gg]>ss){
gg--;
}
if(gg<0) count--;
}
return count;
}
};
0%