面试
c++11 智能指针
进程和线程切换的区别
切换进程空间,TLB失效tcp三次握手协商内容
brk和mmap
1
2
3
4
5
6
7
8#include <unistd.h>
#include <stdio.h>
void main()
{
char *p = sbrk(0);
p[4096] = 1; // segment fault
}引用和指针的区别
epoll/poll/select的区别 (IO多路复用)
https://segmentfault.com/a/1190000003063859笔试
找到数组中某一个元素第一次出现的位置,没有出现返回-1
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
using namespace std;
/**
* find first location of an element in an array, return -1 if not found;
*
*/
int find(vector<int>& nums, int target, int start, int end) {
int len = end - start;
if (len <= 0) return -1;
int mid = start + len / 2;
if ( nums[mid] == target ) {
int res = mid;
for ( int i = mid - 1; i >= start ; i -- ) {
if (nums[i] == target) res = i;
}
return res;
} else if ( nums[mid] > target ) {
return find(nums, target, start , mid - 1);
} else {
return find(nums, target, mid + 1 , end);
}
}
int main() {
vector<int> nums = {0, 1, 1, 1, 3, 5, 6, 6};
std::cout << find(nums, 1, 0, nums.size() - 1) << "\n";
}
射箭游戏,一次分数在0-10之间,输出10次射击最后分数为90的所有结果
1 |
|
逆转单向链表最后k个元素
1 |
|