文远知行 C++ 社招 技术一面
跟字节的一面比起来 太简单了 字节简直是焦作人
1. 项目
略
2. C++模板 之可变参数模板
略
3. C++多态
略
字节对齐
struct A{
bool a;
bool b;
bool c;
int i;
bool d;
};
struct B{
bool a;
bool b;
bool c;
bool d;
int i;
};
//二者有什么区别
4 算法
相比于其他的面试中直接给出现成的题目,文远是现场给需求,边说边写,比如链表要求带虚拟头节点的和不带头结点的情况
4.1. 自定义链表数据结构 反转链表 太简单了哈
递归 也可以做
小哥看着很年轻 开始他说 我这样写反不过来 我还解释了一通🤣
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* cur = NULL, *pre = head;
while (pre) {
ListNode* temp = pre->next;
pre->next = cur;
cur = pre;
pre = temp;
}
return cur;
}
}; 4.2 岛屿数量
入门的DFS 抛开算法本身,需要注意的就是编写接口给用户使用的时候,一定要注意接口是用户友好型的,一般情况不修改用户的输入
#include <functional>
#include <vector>
int numIslands(const std::vector<std::vector<char>> &grid);
int main(int argc, char **argv)
{
//假设每次都输入一个陆地集合
std::vector<std::vector<char>> grid;
return numIslands(grid);
}
int numIslands(const std::vector<std::vector<char>> &grid)
{
int row = grid.size();
int col = grid[0].size();
if (row == 0 || col == 0)
return 0;
int res = 0;
std::vector<std::vector<char>> work_grid = grid;
std::function<void(int, int)> DFS = [&](int x, int y)
{
if (x < 0 || x >= row || y < 0 || y >= col || work_grid[x][y] == '0')
return;
work_grid[x][y] = '0';
DFS(x + 1, y);
DFS(x - 1, y);
DFS(x, y + 1);
DFS(x, y - 1);
};
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
if (work_grid[i][j] == '1')
{
res++;
DFS(i, j);
}
}
}
return res;
} 5. 了解迪杰斯特拉算法不?
6. 了解A*算法不?
不了解
7. 给你一个三角形 和一个点怎么判断这个点在不在三角形内部?
不会
8. 给你两个点构成直线 和一个点怎么判断这个这个点在线的左边还是右边?
不会

360集团公司福利 405人发布