2026年AI算法工程师面试题目与答案.docxVIP

  • 0
  • 0
  • 约5.15千字
  • 约 16页
  • 2026-05-30 发布于福建
  • 举报

第PAGE页共NUMPAGES页

2026年AI算法工程师面试题目与答案

一、编程基础与数据结构(共5题,每题6分,总分30分)

1.题目(6分):

实现一个函数,输入一个整数数组,返回数组中所有唯一数的乘积。如果数组为空或所有元素都重复,返回0。

答案:

python

defunique_product(nums):

fromcollectionsimportCounter

count=Counter(nums)

product=1

fornum,freqincount.items():

iffreq==1:

product=num

returnproductifproduct!=1else0

解析:

使用`Counter`统计每个数字的频率,遍历统计结果,仅当频率为1时乘入结果。若最终乘积为1(即数组为空或无唯一数),返回0。

2.题目(6分):

给定一个链表,反转其前n个节点,并返回反转后的链表头。

答案:

python

classListNode:

def__init__(self,val=0,next=None):

self.val=val

self.next=next

defreverse_head(head,n):

ifnotheadorn==0:

returnhead

文档评论(0)

1亿VIP精品文档

相关文档