面试心得 --- 滴滴三面

滴滴三面的题目是算法 + 项目

算法是洗牌算法


解决方案如下:


void MySwap(int &x, int &y)
{
    int temp = x;
    x = y;
    y = temp;
}

void Shuffle(int n)
{
    for(int i=n-1; i>=1; i--)
    {
        MySwap(num[i], num[rand()%(i+1)]);
    }
}






猜你喜欢

转载自blog.csdn.net/u012965373/article/details/77602632