zoukankan      html  css  js  c++  java
  • 创新工场笔试题

    1.树的子结构问题,参照《剑指offer》上面试题18.

    bool DoseTree1HaveTree2(BinaryTreeNode *pRoot1, BinaryTreeNode *pRoot2)
    {
        if(pRoot2 == NULL)
            return true;
        if(pRoot1 == NULL)
            return false;
        if(pRoot1->m_nValue != pRoot2->m_nValue)
            return false;
        return DoseTree1HaveTree2(pRoot1->m_pLeft, pRoot2->m_pLeft) && DoseTree1HaveTree2(pRoot1->m_pRight, pRoot2->m_pRight);
    }
    
    bool HasSubTree(BinaryTreeNode *pRoot1, BinaryTreeNode *pRoot2)
    {
        bool result = false;
        if(pRoot1 != NULL && pRoot1 != NULL)
        {
            result = DoesTree1HaveTree2(pRoot1, pRoot2);
            if(!result)
                result = HasSubTree(pRoot1->m_pLeft, pRoot2);
            if(!result)
                result = HasSubTree(pRoot1->m_pRight, pRoot2);
        }
        return result;
    }

    2.翻转字符串;

    void reverse(string s)
    {
        int n = s.size();
        int i = 0, j = n-1;
        while(i <= j)
        {
            swap(s[i], s[j]);
            i++;
            j--;
        }
    }

    3.加油站问题,参见leetcode题目Gas Station

    int canCompleteCircuit(vector<int> &gas, vector<int> &cost) {
        int n=gas.size();
        if(n==0)
            return -1;
        int sum=0;
        int dif=0;
        int result=0;
        for(int i=0;i<n;i++)
        {
            sum+=gas[i]-cost[i];
            dif+=gas[i]-cost[i];
            if(sum<0)
            {
                result=(i+1)%n;
                sum=0;
            }
        }
        if(dif<0)
            return -1;
        return result;
    }
  • 相关阅读:
    uboot misc
    Android Q dynamic partition
    Android Verified Boot 2.0简要
    dts参考资料
    SWT问题分析总结
    lzma文件及命令简介
    C++之继承
    C++之常指针
    C++之对象成员指针
    C++之对象指针
  • 原文地址:https://www.cnblogs.com/awy-blog/p/3991578.html
Copyright © 2011-2022 走看看