AcWing

8.8万

LvTao
U+1D405
xueli

chyMIT2028

brivia

dsc182
Tea.

kukudewen

Timi

#### 欧拉图

class Solution {
public:
vector<vector<int>> ans;
map<int, vector<int>> g;
map<int, int> deg;

void dfs(int u) {
auto &ele = g[u];
while (!ele.empty()) {
int p = ele.back();
ele.pop_back();
dfs(p);
ans.push_back({u, p});
}
}

vector<vector<int>> validArrangement(vector<vector<int>>& pairs) {
for (auto &ele: pairs) {
g[ele[0]].push_back(ele[1]);
deg[ele[0]] --;
deg[ele[1]] ++;
}

for (auto itr = deg.begin(); itr != deg.end(); itr ++) {
if (itr->second == -1) {
dfs(itr->first);
break;
}
}

if (ans.size() == 0) {
dfs(deg.begin()->first);
}
reverse(ans.begin(), ans.end());
return ans;
}
};


#### 迭代

class Solution {
public:

bool check(int num) {
if (num == 0) return false;
if (num & 1) return false;
if (num < 100) return false;
return true;
}

vector<int> findEvenNumbers(vector<int>& digits) {
int n = digits.size();
set<int> st;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
if (j == i) continue;
for (int k = 0; k < n; k ++) {
if (k == i || k == j) continue;
int num = 0;
num = digits[i] * 100 + digits[j] * 10 + digits[k];
if (check(num)) {
st.insert(num);
}
}
}
}
vector<int> ans;
for (auto &ele: st) {
ans.push_back(ele);
}

return ans;
}
};


#### 模拟

/**
* 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:
int n = 0;
while (p) {
n ++;
p = p->next;
}
int mid = n / 2;
auto dummy = new ListNode(-1);
p = dummy;
auto q = p->next;
for (int i = 0; i < mid; i ++) {
p = p->next;
q = q->next;
}
p->next = q->next;
return dummy->next;
}
};


#### 最近公共祖先

/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode() : val(0), left(nullptr), right(nullptr) {}
*     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
*     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
bool check(TreeNode* root, int x, string& str){
if(root->val == x) return true;
if(root->left){
str.push_back('L');
if(check(root->left, x, str)) return true;
str.pop_back();
}
if(root->right){
str.push_back('R');
if(check(root->right, x, str)) return true;
str.pop_back();
}
return false;
}

string getDirections(TreeNode* root, int s, int d) {
string strStart, strEnd;

check(root, s, strStart);
check(root, d, strEnd);

int idx = 0;
while (idx < strStart.size()) {
if (strStart[idx] == strEnd[idx]) idx ++;
else break;
}

string left, right;
int n = strStart.size();
if (idx == 0) {
for (int i = 0; i < n; i ++) {
left += "U";
}
right = strEnd;
} else {
for (int i = 0; i < n - idx; i ++) {
left += "U";
}
right = strEnd.substr(idx);
}

return left + right;
}
};


#### 将远程仓库下载到云端服务器上

1.先在ac.git上将该云端服务器的ssh公钥添加
2.git clone将仓库中的代码下载到本地指定位置


#### 分支合并

git merge dev

git commit


#### 切换分支

git checkout master

git commit


#### 新建分支

//创建dev分支
git checkout -b dev

//将dev分支推送到云端
git push --set-upstream origin dev



#### 创建分支

git push --set-upstream origin branch_name


#### 按照要求修改文件，并提交

rm problem2 -r
mkdir problem3
cd problem3
vim main.cpp