2025年計算機編程技術(shù)面試題庫_第1頁
2025年計算機編程技術(shù)面試題庫_第2頁
2025年計算機編程技術(shù)面試題庫_第3頁
2025年計算機編程技術(shù)面試題庫_第4頁
2025年計算機編程技術(shù)面試題庫_第5頁
已閱讀5頁,還剩25頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

2025年計算機編程技術(shù)面試題庫1.代碼填空題(共5題,每題10分)題目1請?zhí)羁胀瓿梢韵翵avaScript代碼,使其能夠正確計算數(shù)組中所有正數(shù)的平均值。javascriptfunctioncalculatePositiveAverage(arr){letsum=0;letcount=0;for(leti=0;i<arr.length;i++){if(arr[i]>0){sum+=______;count++;}}returncount>0?______:0;}題目2請?zhí)羁胀瓿梢韵翽ython代碼,使其能夠反轉(zhuǎn)一個字符串。pythondefreverse_string(s):returns[______:______]題目3請?zhí)羁胀瓿梢韵翵ava代碼,使其能夠判斷一個整數(shù)是否為偶數(shù)。javapublicbooleanisEven(intnum){returnnum%2==______;}題目4請?zhí)羁胀瓿梢韵翪++代碼,使其能夠找出一個數(shù)組中的最大值。cppintfindMax(intarr[],intsize){intmax=arr[0];for(inti=1;i<size;i++){if(arr[i]>______){max=arr[i];}}returnmax;}題目5請?zhí)羁胀瓿梢韵翽ython代碼,使其能夠計算一個列表中所有元素的平方和。pythondefsquare_sum(lst):returnsum([x2forxin______])答案答案1javascriptfunctioncalculatePositiveAverage(arr){letsum=0;letcount=0;for(leti=0;i<arr.length;i++){if(arr[i]>0){sum+=arr[i];count++;}}returncount>0?sum/count:0;}答案2pythondefreverse_string(s):returns[::-1]答案3javapublicbooleanisEven(intnum){returnnum%2==0;}答案4cppintfindMax(intarr[],intsize){intmax=arr[0];for(inti=1;i<size;i++){if(arr[i]>max){max=arr[i];}}returnmax;}答案5pythondefsquare_sum(lst):returnsum([x2forxinlst])2.編程實現(xiàn)題(共5題,每題15分)題目1請用Python實現(xiàn)一個函數(shù),該函數(shù)接收一個字符串,返回該字符串中所有重復字符的列表(不區(qū)分大小寫),每個字符只出現(xiàn)一次。題目2請用Java實現(xiàn)一個方法,該方法接收一個整數(shù)數(shù)組,返回一個新數(shù)組,新數(shù)組中的元素為原數(shù)組中每個元素的平方,且順序不變。題目3請用JavaScript實現(xiàn)一個函數(shù),該函數(shù)接收一個正整數(shù)n,返回一個包含前n個斐波那契數(shù)的數(shù)組。題目4請用C++實現(xiàn)一個函數(shù),該函數(shù)接收一個字符串,返回該字符串的長度,但不計算空格字符。題目5請用Python實現(xiàn)一個類,該類包含一個方法,能夠判斷一個給定的正整數(shù)是否為素數(shù)。答案答案1pythondeffind_duplicates(s):s_lower=s.lower()duplicates=[]forcharins_lower:ifs_lower.count(char)>1andcharnotinduplicates:duplicates.append(char)returnduplicates答案2javapublicint[]squareArray(int[]arr){int[]squared=newint[arr.length];for(inti=0;i<arr.length;i++){squared[i]=arr[i]*arr[i];}returnsquared;}答案3javascriptfunctionfibonacci(n){letfib=[0,1];for(leti=2;i<n;i++){fib[i]=fib[i-1]+fib[i-2];}returnfib.slice(0,n);}答案4cppintcustomLength(conststd::string&str){intlength=0;for(charc:str){if(c!=''){length++;}}returnlength;}答案5pythonclassPrimeChecker:defis_prime(self,num):ifnum<=1:returnFalseforiinrange(2,int(num0.5)+1):ifnum%i==0:returnFalsereturnTrue3.算法題(共5題,每題20分)題目1給定一個整數(shù)數(shù)組,返回數(shù)組中第三大的數(shù)。如果數(shù)組中沒有第三大的數(shù),則返回最大的數(shù)。題目2給定一個字符串,請找到其中不重復的最長子串的長度。題目3給定一個二維網(wǎng)格,每個格子中的數(shù)字表示該格子的高度。找出一條從左上角到右下角的路徑,使得路徑上的數(shù)字之和最小。每次只能向下或向右移動。題目4給定一個非空鏈表,刪除鏈表的倒數(shù)第n個節(jié)點,并返回鏈表的頭節(jié)點。題目5給定一個包含n個整數(shù)的數(shù)組,判斷該數(shù)組是否可以劃分為至少兩個連續(xù)的子數(shù)組,每個子數(shù)組的和都相等。答案答案1pythondefthird_largest(nums):first,second,third=float('-inf'),float('-inf'),float('-inf')fornuminnums:ifnum>first:third,second,first=second,first,numelifnum>second:third,second=second,numelifnum>third:third=numreturnfirstifthird!=float('-inf')elsesecond答案2pythondeflength_of_longest_substring(s):char_map={}left=0max_length=0forrightinrange(len(s)):ifs[right]inchar_mapandchar_map[s[right]]>=left:left=char_map[s[right]]+1char_map[s[right]]=rightmax_length=max(max_length,right-left+1)returnmax_length答案3pythondefmin_path_sum(grid):ifnotgridornotgrid[0]:return0m,n=len(grid),len(grid[0])dp=[[0]*nfor_inrange(m)]dp[0][0]=grid[0][0]foriinrange(1,m):dp[i][0]=dp[i-1][0]+grid[i][0]forjinrange(1,n):dp[0][j]=dp[0][j-1]+grid[0][j]foriinrange(1,m):forjinrange(1,n):dp[i][j]=min(dp[i-1][j],dp[i][j-1])+grid[i][j]returndp[-1][-1]答案4pythondefremoveNthFromEnd(head,n):dummy=ListNode(0)dummy.next=headfirst=dummysecond=dummyfor_inrange(n+1):first=first.nextwhilefirst:first=first.nextsecond=second.nextsecond.next=second.next.nextreturndummy.next答案5pythondefcan_partition(nums):total_sum=sum(nums)iftotal_sum%2!=0:returnFalsetarget=total_sum//2dp=[False]*(target+1)dp[0]=Truefornuminnums:forjinrange(target,num-1,-1):dp[j]=dp[j]ordp[j-num]returndp[target]4.數(shù)據(jù)結(jié)構(gòu)題(共5題,每題20分)題目1請用Python實現(xiàn)一個棧類,該類支持push、pop和isEmpty操作。題目2請用Java實現(xiàn)一個隊列類,該類使用兩個棧實現(xiàn)隊列的操作。題目3請用C++實現(xiàn)一個二叉搜索樹類,該類支持插入和查找操作。題目4請用JavaScript實現(xiàn)一個雙向鏈表類,該類支持append、prepend和remove操作。題目5請用Python實現(xiàn)一個哈希表類,該類使用鏈表解決哈希沖突。答案答案1pythonclassStack:def__init__(self):self.items=[]defpush(self,item):self.items.append(item)defpop(self):ifnotself.isEmpty():returnself.items.pop()returnNonedefisEmpty(self):returnlen(self.items)==0答案2javaimportjava.util.Stack;publicclassQueueWithStacks{privateStack<Integer>stack1;privateStack<Integer>stack2;publicQueueWithStacks(){stack1=newStack<>();stack2=newStack<>();}publicvoidenqueue(intitem){stack1.push(item);}publicintdequeue(){if(stack2.isEmpty()){while(!stack1.isEmpty()){stack2.push(stack1.pop());}}returnstack2.pop();}publicbooleanisEmpty(){returnstack1.isEmpty()&&stack2.isEmpty();}}答案3cpp#include<iostream>usingnamespacestd;structTreeNode{intval;TreeNode*left;TreeNode*right;TreeNode(intx):val(x),left(nullptr),right(nullptr){}};classBST{public:TreeNode*insert(TreeNode*root,intval){if(!root)returnnewTreeNode(val);if(val<root->val)root->left=insert(root->left,val);elseroot->right=insert(root->right,val);returnroot;}boolsearch(TreeNode*root,intval){if(!root)returnfalse;if(root->val==val)returntrue;returnval<root->val?search(root->left,val):search(root->right,val);}};答案4javascriptclassListNode{constructor(val=0,prev=null,next=null){this.val=val;this.prev=prev;this.next=next;}}classDoublyLinkedList{constructor(){this.head=null;this.tail=null;}append(val){constnewNode=newListNode(val);if(!this.head){this.head=this.tail=newNode;}else{newNode.prev=this.tail;this.tail.next=newNode;this.tail=newNode;}}prepend(val){constnewNode=newListNode(val);if(!this.head){this.head=this.tail=newNode;}else{newNode.next=this.head;this.head.prev=newNode;this.head=newNode;}}remove(node){if(!node)return;if(node.prev){node.prev.next=node.next;}else{this.head=node.next;}if(node.next){node.next.prev=node.prev;}else{this.tail=node.prev;}}}答案5pythonclassListNode:def__init__(self,key=None,value=None):self.key=keyself.value=valueself.next=NoneclassHashTable:def__init__(self,size=100):self.size=sizeself.table=[None]*self.sizedef_hash(self,key):returnhash(key)%self.sizedefinsert(self,key,value):index=self._hash(key)node=self.table[index]ifnotnode:self.table[index]=ListNode(key,value)else:prev=Nonewhilenode:ifnode.key==key:node.value=valuereturnprev=nodenode=node.nextprev.next=ListNode(key,value)defget(self,key):index=self._hash(key)node=self.table[index]whilenode:ifnode.key==key:returnnode.valuenode=node.nextreturnNone5.面試綜合題(共5題,每題25分)題目1請設(shè)計一個算法,找出數(shù)組中重復次數(shù)最多的元素,并返回其重復次數(shù)。題目2請設(shè)計一個算法,將一個字符串中的所有字母移到字符串的左邊,所有非字母字符移到字符串的右邊,并保持字母和非字母字符的相對順序不變。題目3請設(shè)計一個算法,判斷一個給定的鏈表是否為回文鏈表。題目4請設(shè)計一個算法,找出二叉樹中所有路徑和等于給定數(shù)字的路徑。題目5請設(shè)計一個算法,實現(xiàn)一個簡單的LRU(最近最少使用)緩存,支持get和put操作。答案答案1pythondefmost_frequent(nums):count={}max_count=0most_freq=Nonefornuminnums:count[num]=count.get(num,0)+1ifcount[num]>max_count:max_count=count[num]most_freq=numreturnmax_count答案2pythondefreorderString(s):letters=[]non_letters=[]forcins:ifc.isalpha():letters.append(c)else:non_letters.append(c)return''.join(letters+non_letters)答案3pythondefisPalindrome(head):ifnotheadornothead.next:returnTrueslow=headfast=headprev=Nonewhilefastandfast.next:fast=fast.next.nextprev,slow.next=slow,prevslow=slow.nextiffast:slow=slow.nextwhileslow:ifslow.val!=prev.val:returnFalseslow=slow.nextprev=prev.nextreturnTrue答案4pythondefpathSum(root,sum):result=[]defdfs(node,current_sum,path):ifnotnode:returncurrent_sum+=node.valpath.append(node.val)ifcurrent_sum==sum:res

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論