阿里巴人工智能部主任工程师面试题集.docxVIP

  • 0
  • 0
  • 约9.77千字
  • 约 25页
  • 2026-11-07 发布于福建
  • 举报

阿里巴人工智能部主任工程师面试题集.docx

第PAGE页共NUMPAGES页

2026年阿里巴人工智能部主任工程师面试题集

一、算法与数据结构(共5题,每题10分,总分50分)

题目1(10分)

设计一个算法,找出数组中第三大的数。要求时间复杂度为O(n),空间复杂度为O(1)。假设数组中没有重复元素。

答案与解析:

python

defthird_largest(nums):

first,second,third=float(-inf),float(-inf),float(-inf)

fornuminnums:

ifnumfirst:

third=second

second=first

first=num

eliffirstnumsecond:

third=second

second=num

elifsecondnumthird:

third=num

returnthirdifthird!=float(-inf)elseNone

解析:初始化三个变量first、second、third为负无穷大,遍历数组时不断更新这三个变量的值。如果当前数大于first,则更新first、second、third;如果当前数介于first和second之间,则更新second和third;如果当前数介于second和third之间,则只更新t

文档评论(0)

1亿VIP精品文档

相关文档