ARTS-week16

Algorithms

Binary Tree Level Order Traversal

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
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
if (root == NULL) {
return res;
}
preorder(root, 0);
return res;
}
private:
vector<vector<int>> res;

void preorder(TreeNode* root, int level) {
while (res.size() <= level) {
res.push_back(vector<int>());
}
res[level].push_back(root->val);
if (root->left != NULL) {
preorder(root->left, level + 1);
}
if (root->right != NULL) {
preorder(root->right, level + 1);
}
}
};

Binary Tree Level Order Traversal II

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
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int>> levelOrderBottom(TreeNode* root) {
if (root == NULL) {
return res;
}
levelOrder(root, 0);
reverse(res.begin(), res.end());
return res;
}
private:
vector<vector<int>> res;
void levelOrder(TreeNode* root, int level) {
if (res.size() <= level) {
res.push_back(vector<int>());
}
res[level].push_back(root->val);
if (root->left != NULL) {
levelOrder(root->left, level + 1);
}
if (root->right != NULL) {
levelOrder(root->right, level + 1);
}
}
};

Review

本周阅读英文文章 A new class of zero days and autonomous weapons systems

Adversarial examples are inputs to machine learning models that an attacker has intentionally designed to cause the model to make a mistake; they’re like optical illusions for machines.

Using the same zero day logic, adversarial training attempts to train the artificial intelligence algorithm to recognise false positives, and react in the way that it was designed even when hostile actors try to trick the artificial intelligence. But just like with code, the creators of the algorithm and the testers of the algorithm may not have thought of all the ways in which hostile actors can trick the AI.

Technique

本周在项目中遇到了使用递归宏的代码,如下是其中的一行:

1
#define MAP(f, ...) EVAL (MAP1 (f, __VA_ARGS__, (), 0))

开始并没看懂,在StackOverflow中找到了详细的解释:
https://stackoverflow.com/questions/6707148/foreach-macro-on-macros-arguments

https://github.com/swansontec/map-macro

Share

在看《从0开始学微服务》中微服务多机房部署实践中提到四层负载均衡器VIP以及七层负载均衡器Nginx时,有点懵,自己没有做过类似的项目和知识储备,就查了一下。

具体看了以下关于负载均衡相关的文章:

https://kb.cnblogs.com/page/188170/

https://tech.meituan.com/MGW.html

0%