2020华为校招软件测试:专业面试两轮的算法题

专业面试笔试题1:计算二叉树的深度 

public int computeTreeDepth(BinaryTree binaryTree){
        if(binaryTree == null){
            return 0;
        }
        if(binaryTree.lChild == null && binaryTree.rChild == null){
            return 1;
        }
        int lDepth = computeTreeDepth(binaryTree.lChild) + 1;
        int rDepth = computeTreeDepth(binaryTree.rChild) + 1;
        return Math.max(lDepth, rDepth);
    }


专业面试笔试题2:反转数字,输入一个32位整形数字a,输出反转后的数字,例如:123,输出321;-2324,输出-4232;1003400,输出43001;如果输入的数超过32位,则输出0;
 

#include 
#include 
using namespace std;
int main() {
    int a,b=0,c[10],weiShu;
    cin >> a;
    
    if(a<-2147483647 || a>2147483647){
        b=1;
        cout<=0; j--){
        if(c[j] != 0){
            weiShu = j;
            break;
        }
    }
    //反转
    for(int z=weiShu; z>=0; z--){
        b = b+c[z]*pow(10,weiShu-z);
    }
    cout<

 

你可能感兴趣的:(软件测试)