文章目录
微信事业群一、二面
一面
时长:1小时30分钟
时间:2019/8/31
一分钟自我介绍
一、算法
1、手写代码实现字符串反转
public String stringReverse (String inputString) {
int length = inputString.length();
if (inputString == null || length == 0) {
return null;
}
return reverse(inputString.toCharArray(), 0, length-1);
}
private String reverse (char[] array, int start, int end) {
while (start < end) {
char temp = array[start];
array[start++] = array[end];
array[end--] = temp;
}
return array.toString();
}
2、手写双向链表
public class LinkedList{
private Node root;
public class Node{
private int data;
private Node preNode;
private Node next;
}
public Node getRoot(){
return this.root;
}
public void setRoot(Node root) {
this.root = root;
}
}
3、按照顺序合并两个链表
public static Node mergeTwoLinkedList(Node head1,Node head2){
//两个链表都为空,返回空
if(head1==null&&head2==null)
return null;
//任一一个为空返回另一个
if(head1==null)
return head2;
if(head2==null)
return head1;
Node reHead; //新链表的头结点
Node temp;
//初始化新链表的头结点
if(head1.data<head2.data){
reHead=head1;
temp=head1;
head1=head1.next;
}else{
reHead=head2;
temp=head2;
head2=head2.next;
}
//两个链表逐个结点开始比较,
while(head1!=null&&head2!=null){
if(head1.data<head2.data){
temp.next=head1;
head1=head1.next;
temp=temp.next;
}else{
temp.next=head2;
head2=head2.next;
temp=temp.next;
}
}