欢聚时代笔试题目
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;
}
};
