2026年腾讯技术部招聘面试题库与参考答案.docxVIP

  • 0
  • 0
  • 约7.86千字
  • 约 24页
  • 2026-01-21 发布于福建
  • 举报

2026年腾讯技术部招聘面试题库与参考答案.docx

第PAGE页共NUMPAGES页

2026年腾讯技术部招聘面试题库与参考答案

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

1.题目:

给定一个字符串,请编写一个函数,找出其中不重复的字符,并按顺序返回这些字符组成的字符串。例如,输入`leetcode`,输出`ld`。

参考答案:

cpp

includeiostream

includestring

includeunordered_map

includevector

std::stringfindUniqChars(conststd::strings){

std::unordered_mapchar,intcount;

for(charc:s){

count[c]++;

}

std::stringresult;

for(charc:s){

if(count[c]==1){

result+=c;

}

}

returnresult;

}

intmain(){

std::stringinput=leetcode;

std::coutfindUniqChars(input)std::endl;//输出ld

return0;

}

解析:

使用哈希表统计每个字符的出现次数,遍历字符串时仅将计数为1的字符加入结果。时间复杂度O(n),空间复杂度O(

文档评论(0)

1亿VIP精品文档

相关文档