八股文
- ip地址的分类
- 特殊ip地址
- DNS服务器介绍
- http协议状态码:502,404,200
- cookie & session
- c++中的多态
- 平时是如何自学的
linux
- 写一个 查找一个log文件中,每个ip地址出现了多少次 的shell脚本,使用awk命令实现查找
- 如果这个文件很大,上了10g怎么半
算法
二叉树中找出满足节点和为某一给定值k的所有路径
注: 根节点到叶子节点路径
原题的leetcode链接:leetcode113
#include<vector>
#include<queue>
#include <iostream>
using namespace std;
vector<vector<int> > routes;
struct treenode{
int val;
treenode* left;
treenode* right;
treenode(): val(0), left(nullptr), right(nullptr){}
treenode(int _val): val(_val), left(nullptr), right(nullptr){}
};
void findall(treenode* root, vector<int> curroute, int cursum, int k){
if(root == nullptr) return;
if(cursum + root->val == k && root->left == nullptr && root->right == nullptr){
curroute.push_back(root->val);
routes.push_back(curroute);
return;
}
cursum += root->val;
curroute.push_back(root->val);
if(root->left) findall(root->left, curroute, cursum, k);
if(root->right) findall(root->right, curroute, cursum, k);
}
int main() {
treenode* root = new treenode(1);
treenode* left1 = new treenode(2);
treenode* right1 = new treenode(3);
root->left = left1;
root->right = right1;
treenode* child4 = new treenode(4);
left1->left = child4;
child4->left = new treenode(2);
left1->right = new treenode(5);
right1->right = new treenode(3);
int k = 7;
vector<int> vec;
findall(root, vec, 0, k);
for(auto route : routes){
for(auto t : route){
cout << t << " ";
}
cout << endl;
}
}
代码实际输出:1 3 3