腾讯公司技术创新面试题及答案.docxVIP

  • 1
  • 0
  • 约7.59千字
  • 约 22页
  • 2026-11-09 发布于福建
  • 举报

第PAGE页共NUMPAGES页

2026年腾讯公司技术创新面试题及答案

一、编程实现题(共3题,每题15分,总分45分)

题目1(15分):

请实现一个函数,输入一个非负整数数组,返回其中第三大的数。如果数组中没有第三大的数,则返回最大的数。

示例:

输入:[3,2,1,5,6,4]

输出:4

输入:[1,2]

输出:2

要求:

1.时间复杂度不超过O(n)。

2.不能使用排序。

答案与解析:

cpp

includevector

includeclimits

usingnamespacestd;

intthirdMax(vectorintnums){

longfirst=LONG_MIN,second=LONG_MIN,third=LONG_MIN;

for(intnum:nums){

if(numfirst){

third=second;

second=first;

first=num;

}elseif(numsecondnumfirst){

third=second;

second=num;

}elseif(numthirdnumsecond){

third=num;

}

}

return(third==LONG_MIN)?

文档评论(0)

1亿VIP精品文档

相关文档