1. 程式人生 > >Unity Technologies 2019 校招面試總結

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;     } };

筆試:

/*-----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;
	}
};

/*-----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;
}