赞
踩
2022/1/5
首先是电面,时长一小时。
自我介绍+项目介绍+实习内容+中间穿插问题。
coding:反转链表、k个一组翻转链表(lc原题改进,不同之处在于不满k个也要反转,细节比较多)
#include <iostream>
using namespace std;
// 链表反转
struct ListNode{
int val;
ListNode* next;
ListNode():val(0),next(NULL){}
ListNode(int x,ListNode* next):val(x),next(next){}
};
ListNode* reverseList(ListNode* head){
ListNode* prev = NULL;
ListNode* curr = head;
while(curr){
ListNode* next = curr->next;
curr->next = prev;
prev= curr;
curr = next;
}
return prev;
}
ListNode* NreverseList(ListNode* head,int N){
ListNode* slow = nullptr;
ListNode* fast = nullptr;
ListNode* newhead = new ListNode();
ListNode* curr=newhead;
while(head){
slow = head;
fast = head;
int count =N;
while(count>1 && fast->next){
fast = fast->next;
count--;
}
head = fast->next;
fast->next = NULL;
curr->next = reverseList(slow);
curr = slow;
}
curr->next = head;
return newhead->next;
}
int main(){
ListNode* head = new ListNode(1,NULL);
ListNode* first = new ListNode(2,NULL);
ListNode* second = new ListNode(3,NULL);
ListNode* third = new ListNode(4,NULL);
ListNode* fourth = new ListNode(5,NULL);
ListNode* fifth = new ListNode(6,NULL);
ListNode* sixth = new ListNode(7,NULL);
ListNode* seventh = new ListNode(8,NULL);
head->next = first;
first->next = second;
second->next=third;
third->next= fourth;
fourth->next = fifth;
fifth->next = sixth;
sixth->next = seventh;
ListNode* newhead;
int N =3;
newhead = NreverseList(head,N);
ListNode* curr = newhead;
while(curr){
cout<<curr->val<<" ";
curr = curr->next;
}
}
// 1,2,3,4,5,6,7,8 3 => 3,2,1,6,5,4,8,7
面试官人很好,面试体验很好。
——————————————————————————
然后是一面,
coding:给定仅由0和若干个1组成的数组,仅修改两个0为1,让1和1之间的最小距离最大,值为多少?
/*
[0,1,0,1,0,1] min_dist = 1
[1, 0, 0, 0, 0, 0, 1] min_dist = 5
[0,0, 0, 1, 0, 0, 0, 0, 0, 1, ]
[1, 0, 1, 0, 1, 0, 1] min_dist = 1
[1, 1, 0, 0, 1, 0, 1] min_dist = 0
*/
——————————————————————————
然后是二面:
sql索引(这里整理一下)
c++中的static(这里也整理一下)
coding:连续子数组的最小和
连续子数组绝对值的最小和
后面的两轮个人原因因为自己真的状态不好,就到此为止了。
最后补充一道另一家公司的题目:
给出一个元素无序的数组,求出一个数,使得其左边的数都小于它,右边的数都大于等于它。要求时间复杂度为O(n)。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。