2026年IT公司软件开发工程师面试题及答案.docxVIP

  • 1
  • 0
  • 约8.67千字
  • 约 26页
  • 2026-01-16 发布于福建
  • 举报

2026年IT公司软件开发工程师面试题及答案.docx

第PAGE页共NUMPAGES页

2026年IT公司软件开发工程师面试题及答案

一、编程语言基础(5题,每题10分,共50分)

1.题目(Java):

编写一个Java方法,实现将字符串中的所有空格替换为`%20`。假设字符串的长度足够容纳替换后的结果,且输入字符串只包含字母、空格和标点符号。

答案:

java

publicclassReplaceSpaces{

publicstaticStringreplaceSpaces(Strings){

if(s==null)returnnull;

StringBuildersb=newStringBuilder();

for(charc:s.toCharArray()){

if(c==){

sb.append(%20);

}else{

sb.append(c);

}

}

returnsb.toString();

}

publicstaticvoidmain(String[]args){

Stringinput=HelloWorld;

System.out.println(replaceSpaces(input));//输出:Hello%20World

}

}

解析:

通过遍历字符串的每个字符,当遇到空格时替换为`%20`,否则直接追加字符。使用`StringBuilder`优化性能,避免频繁的字符串拼接。

2.题目(Python):

编写一个Python函数,接收一个列表,返回列表中所有偶数的平方,并按升序排列。

答案:

python

defeven_square_sort(nums):

returnsorted([x2forxinnumsifx%2==0])

示例

print(even_square_sort([1,2,3,4,5]))#输出:[4,16]

解析:

使用列表推导式筛选偶数并计算平方,然后使用`sorted()`函数进行升序排序。

3.题目(C++):

实现一个C++函数,计算两个正整数的最大公约数(GCD),要求使用辗转相除法。

答案:

cpp

includeiostream

usingnamespacestd;

intgcd(inta,intb){

while(b!=0){

inttemp=b;

b=a%b;

a=temp;

}

returna;

}

intmain(){

coutgcd(48,18)endl;//输出:6

return0;

}

解析:

辗转相除法通过循环将较大数除以较小数,直到余数为0,此时较小数为最大公约数。

4.题目(JavaScript):

编写一个JavaScript函数,检查一个字符串是否是回文(正序和倒序相同)。

答案:

javascript

functionisPalindrome(str){

constcleaned=str.toLowerCase().replace(/[^a-z0-9]/g,);

letleft=0;

letright=cleaned.length-1;

while(leftright){

if(cleaned[left]!==cleaned[right]){

returnfalse;

}

left++;

right--;

}

returntrue;

}

//示例

console.log(isPalindrome(Aman,aplan,acanal:Panama));//输出:true

解析:

先去除字符串中的非字母数字字符并转为小写,然后使用双指针从两端向中间比较字符是否相同。

5.题目(Go):

实现一个Go函数,统计一个字符串中每个字符出现的次数,并返回一个字典(map)。

答案:

go

packagemain

import(

fmt

)

funccountChars(sstring)map[rune]int{

count:=make(map[rune]int)

for_,char:=ranges{

count[char]++

}

returncount

}

funcmain(){

fmt.Println(countChars(hello))//输出:{h:1,e:1,l:2,o:1}

}

解析:

使用`rune`类型遍历字符串的每个字符,并在map中记录出现次数。

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

6.题目(链表):

给定一个链表,删除链表的倒数第N个节点,并返回新的

文档评论(0)

1亿VIP精品文档

相关文档