- 1
- 0
- 约5.36千字
- 约 16页
- 2026-01-28 发布于福建
- 举报
第PAGE页共NUMPAGES页
2026年人工智能应用开发工程师面试题及答案
一、编程语言与基础算法(共5题,每题10分,总分50分)
1.题目:
请用Python实现一个函数,输入一个正整数n,返回其阶乘值。要求使用递归方法,并处理输入非正整数的情况,返回错误提示。
答案:
python
deffactorial(n):
ifnotisinstance(n,int)orn0:
return输入必须是正整数
ifn==0:
return1
returnnfactorial(n-1)
解析:
递归是算法设计的重要方法,本题考察递归逻辑和输入校验。递归的核心是基准情况(n=0时返回1)和递归步骤(nfactorial(n-1))。输入校验确保函数鲁棒性。
2.题目:
给定一个字符串列表words,请写一个函数,返回其中最长的回文子串。例如,输入[abc,car,ada,racecar],返回racecar。
答案:
python
deflongest_palindrome(words):
defexpand_around_center(s,left,right):
whileleft=0andrightlen(s)ands[left]==s[right]:
left-=1
right+=1
returns[left+1:right]
max_palindrome=
forwordinwords:
foriinrange(len(word)):
palindrome1=expand_around_center(word,i,i)#奇数长度
palindrome2=expand_around_center(word,i,i+1)#偶数长度
iflen(palindrome1)len(max_palindrome):
max_palindrome=palindrome1
iflen(palindrome2)len(max_palindrome):
max_palindrome=palindrome2
returnmax_palindrome
解析:
双指针法是解决回文问题的常用技巧。先遍历每个单词,再用中心扩展法检查所有可能的回文子串。时间复杂度O(n2),适合面试场景。
3.题目:
请用Java实现快速排序算法,并说明其时间复杂度和稳定性。
答案:
java
publicclassQuickSort{
publicstaticvoidquickSort(int[]arr,intleft,intright){
if(left=right)return;
intpivotIndex=partition(arr,left,right);
quickSort(arr,left,pivotIndex-1);
quickSort(arr,pivotIndex+1,right);
}
privatestaticintpartition(int[]arr,intleft,intright){
intpivot=arr[right];
inti=left-1;
for(intj=left;jright;j++){
if(arr[j]=pivot){
i++;
swap(arr,i,j);
}
}
swap(arr,i+1,right);
returni+1;
}
privatestaticvoidswap(int[]arr,inti,intj){
inttemp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
解析:
快速排序是分治算法的代表,时间复杂度平均O(nlogn),最坏O(n2)。不稳定排序,因可能改变相等元素的相对顺序。
4.题目:
用C++实现一个无重复字符的最长子串长度计算,例如输入abcabcbb,返回abc的长度3。
答案:
cpp
includeunordered_map
includestring
usingnamespacestd;
intlength_of_longest_substring(strings){
unordered_mapchar,intchar_index;
intleft=0,max_len=0;
for(intright=0;rights.size();++right){
i
您可能关注的文档
最近下载
- NGTsr系统培训教程.pdf VIP
- 合格证模板打印可修改.docx VIP
- 2025年包装设计行业包装印刷与市场趋势报告.docx VIP
- 心血管运动医学指南.pdf
- DL_T 1074-2019 电力用直流和交流一体化不间断电源(代替DL_T 1074-2007).docx VIP
- 小鹅通产品介绍(32页PPT).pptx VIP
- 部编人教版四年级数学上册期末试卷(审定版).doc VIP
- (正式版)D-L∕T 1392-2014 直流电源系统绝缘监测装置技术条件.docx VIP
- 高考英语读后续写热点话题预测梳理 清单-2025届高三年级下册英语三轮复习(全国通用).pdf VIP
- 安全分享——电梯安全.ppt VIP
原创力文档

文档评论(0)