2026年游戏开发岗位面试题目与解答.docxVIP

  • 1
  • 0
  • 约7.37千字
  • 约 19页
  • 2026-02-08 发布于福建
  • 举报

第PAGE页共NUMPAGES页

2026年游戏开发岗位面试题目与解答

一、编程基础与算法(共5题,每题10分,总分50分)

题目1(10分)

题目:请实现一个函数,输入一个整数数组,返回该数组中第三大的数。如果数组中少于三个不同的数,则返回最大的数。

解答:

python

defthird_largest(nums):

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

fornuminnums:

ifnumfirst:

third,second,first=second,first,num

eliffirstnumsecond:

third,second=second,num

elifsecondnumthird:

third=num

returnfirstifthird==float(-inf)elsethird

解析:

-首先初始化三个变量`first`、`second`、`third`为负无穷,用于存储第一大、第二大、第三大的数。

-遍历数组中的每个数,如果当前数大于`first`,则更新三个变量;如果当前数在`first`和`second`之间,则更新`second`和`third`;如果当前数在`second`

文档评论(0)

1亿VIP精品文档

相关文档