Unity Technologies 2019 校招面试总结

宣讲会人太少选择的线上笔试,笔试1h+一面+二面+三面

三面:

写一个简单不加括号正则表达式,如果不合法就返回false

二面:

输出链表中点,智力题

struct ListNode{
    int val;
    ListNode* next;
};

int len(ListNode* head)
{
    int n=0;
    ListNode * node=head;
    while(node!=nullptr)
    {
        n++;
        node=node->next;
    }
}
ListNode * find(ListNode* head)
{
    int length=len(head);
    int n=0;
    
    if(length&1)
        n=length/2+1;
    else
        n=length/2;
    
    ListNode* node=head;
    for(int i=1;i<=n;i++)
    {
        node=node->next;
    }
    
    return node;
}

ListNode* find(ListNode* head)
{
    
    ListNode* p1=head->next;
    ListNode* p2=p1->next;
    
    while(p2!=nullptr&&p2->next!=nullptr)
    {
        p1=p1->next;
        p2=p2->next->next;
    }
    return p1;
}

一面:

笔试题说一遍,C++基础,多态代码

class A{
public:
    virtual void fun(){
        cout << "a" << endl;
    }
};
class B :A{
    virtual void fun(){
        cout << "b" << endl;
    }
};

笔试:

Unity Technologies 2019 校招面试总结

/*-----1 正则表达------*/
class Solution{
public:
	bool Ismatch(char* s, char* p)
	{
		if (!s || !p)
			return false;
		return match(s, p);
	}
	bool match(char* s, char* p)
	{
		if (*s == '\0'&&*p == '\0')
			return true;
		if (*s != '\0'&&*p == '\0')
			return false;

		if (*(p + 1) == '*')
		{
			if ((*p == *s) || (*p == '.'&&*s != '\0'))
			{
				return match(s + 1, p + 2) || match(s + 1, p) || match(s, p + 2);
			}
			else
				return match(s, p + 2);
		}
		if (*p == *s || (*p == '.'&&*s != '\0'))
		{
			return match(s + 1, p + 1);
		}
		return false;
	}
};

Unity Technologies 2019 校招面试总结

 

/*-----3 链表交点------*/

struct ListNode{
	int val;
	ListNode* next;
};
int len(ListNode *head)
{
	int n = 0;
	ListNode *node = head;
	while (node != nullptr)
	{
		n++;
		node = node->next;
	}
	return n;
}
ListNode * getIntersectionNode(ListNode *H1, ListNode* H2)
{
	int n1 = len(H1);
	int n2 = len(H2);
	int n = n1 - n2;

	ListNode *Long = H1;
	ListNode *Short = H2;

	if (n2 > n1)
	{
		Long = H2;
		Short = H1;
		n = n2 - n1;
	}
	for (int i = 0; i < n; i++)
	{
		Long = Long->next;	
	}
	while ((Long != nullptr) && (Short != nullptr) && (Long != Short))
	{
		Long = Long->next;
		Short = Short->next;
	}
	ListNode *Fnode = Long;

	return Fnode;
}

Unity Technologies 2019 校招面试总结