欢聚时代笔试题目

1.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
    /**
     * 将字符串转换为整数输出
     * @param str string字符串 输入字符串
     * @return int整型
     */
    int str2Int(string str) {
        int flag=1;
        // write code here
        if(str[0]=='-') falg=-1;
        int s=0;
        int index=0;
        for(int i=str.size()-1;i>=0;i--)
        {
          if(str[i]!='-')
            s=s+pow(10,index)*(str[i]-'0');
          index++;
        }
        return s*flag;

    }
};
2.
class Solution {
public:
    /**
     * 返回反转后的链表
     * @param Head ListNode类 链表开始结点
     * @return ListNode类
     */
    ListNode* revert_list(ListNode* Head) {
        // write code here
        ListNode*front=NULL;//zheli 
        ListNode*cur=Head;
        while(cur)
        {
          ListNode*temp=cur->next;
          cur->next=front;
          front=cur;
          cur=temp;
        }

        return front;
    }
};


#笔试题目##欢聚集团#
全部评论
lz什么岗
点赞
送花
回复 分享
发布于 2020-08-31 20:04
两道题一共20分,要是招人的话差距都在选择上
点赞
送花
回复 分享
发布于 2020-08-31 20:14
国泰君安
校招火热招聘中
官网直投
第一题不是有个用例是 "214748364789" 2147483647, 这行?
点赞
送花
回复 分享
发布于 2020-08-31 20:20
不是说带头结点吗。为啥连着头结点都逆转了,这还算个啥的头结点。
点赞
送花
回复 分享
发布于 2020-08-31 20:46
有第二题反转链表AC的代码嘛? 我感觉代码没错  始终通过0%
点赞
送花
回复 分享
发布于 2020-08-31 20:56

相关推荐

2 2 评论
分享
牛客网
牛客企业服务