zoukankan      html  css  js  c++  java
  • 寒武纪面试 测试开发

    一面:

    2020.07.29

    链表相交,

    实现memcpy函数,

    newmalloc的区别

     

    memcpy函数的实现:

    void *memcpy(void *pDest, const void*pSrc, unsigned int n) {

    assert((NULL != pDest)&&(NULL != pSrc))

    char *pTmpDest = (char*)pDest;

    char *pTmpSrc = (char*)pSrc;

    while(n--) {

    *pTmpDest = *pTmpSrc;

    pTmpDest++;

    pTmpSrc++;

    }

     

    return pDest;

    }

     

    void* upgrade_memcpy(void* pDest, const void* pSrc, size_t n) {

    assert((pDest!=NULL)&&(pSrc!=NULL))

    int wordnum = n/4;

    int slice = n%4;

    int * pIntsrc =  (int*)pSrc;

    int * pIntdest = (int*)pDest;

     

    while(wordnum--) 
    *pIntdest++ = *Intsrc++;

    while(slice--)

        *((char*)pIntdest)++ = *((char*)pIntsrc)++;

     

    return pDest;

    }

     

    二面

    2020.08.05

    1、多线程

    2、IPC、共享内存

    3、bind

    4、合并n个有序链表 (力扣原题 使用最小堆会快一些)

     

    #include <queue>

    using namespace std;

     

    struct ListNode {

        int val;

        ListNode* next;

        ListNode(int x) : val(x), next(NULL) {}

    };

     

    class Solution {

        struct cmp {

            bool operator() (ListNode* a, ListNode* b) {

                return a->val > b->val;

            }

        };

        

        ListNode* mergeKLists(vector<ListNode*>& lists) {

            priority_queue<ListNode*, vector<ListNode*>, cmp> pri;

            for (auto &elem : lists) {

                if (elem) {

                    pri.push(elem);

                }

            }

            

            ListNode* head = new ListNode(0);

            ListNode* pre = head;

            while(!pri.empty()) {

                pre->next = pri.top();

                ListNode* tmp = pri.top()->next;

                pri.pop();

                if (tmp) {

                    pri.push(tmp);

                }

                pre = pre->next;

            }

            

            pre = head->next;

            delete head;

            

            return pre;

        };

    };

  • 相关阅读:
    java volatile关键字解惑
    Java 反射
    拷贝源实体类到目标实体类中
    Bean和Map之间的转换
    DateUtils时间的封装
    HttpClient的代码封装,便于直接调用
    HttpClient语法
    LinkedHashMap+ConcurrentHashMap+hashMap的区别
    1006 Tick and Tick
    Event Flow
  • 原文地址:https://www.cnblogs.com/xiaohaigegede/p/13520225.html
Copyright © 2011-2022 走看看