招商蛇口资深工程师招聘面试题库含答案.docxVIP

  • 0
  • 0
  • 约6.36千字
  • 约 19页
  • 2026-02-10 发布于福建
  • 举报

招商蛇口资深工程师招聘面试题库含答案.docx

第PAGE页共NUMPAGES页

2026年招商蛇口资深工程师招聘面试题库含答案

一、编程语言与数据结构(共5题,每题10分,总分50分)

题目1(Java编程)

请用Java实现一个方法,输入一个字符串,返回该字符串中最长的不重复字符子串的长度。例如,输入abcabcbb,返回abcbb的长度3。

java

publicintlengthOfLongestSubstring(Strings){

int[]charIndex=newint[128];

intleft=0,maxLen=0;

for(intright=0;rights.length();right++){

charc=s.charAt(right);

left=Math.max(left,charIndex[c]);

maxLen=Math.max(maxLen,right-left+1);

charIndex[c]=right+1;

}

returnmaxLen;

}

解析:采用滑动窗口技术,维护一个字符最后出现位置的数组,遍历时动态调整窗口左边界。时间复杂度O(n),空间复杂度O(1)。

题目2(数据结构)

实现一个LRU(LeastRecentlyUsed)缓存,支持get和put操作。要求get操作返回缓存中对应键的值,如果不存在返回-1;put操作将键值对添加到缓存中,如果缓存已满则删除最久未使用的项。

java

importjava.util.HashMap;

importjava.util.Map;

classLRUCache{

privateMapInteger,Nodecache;

privateNodehead,tail;

privateintcapacity;

classNode{

intkey,value;

Nodeprev,next;

}

publicLRUCache(intcapacity){

this.capacity=capacity;

cache=newHashMap();

head=newNode();

tail=newNode();

head.next=tail;

tail.prev=head;

}

publicintget(intkey){

Nodenode=cache.get(key);

if(node==null)return-1;

moveToHead(node);

returnnode.value;

}

publicvoidput(intkey,intvalue){

Nodenode=cache.get(key);

if(node!=null){

node.value=value;

moveToHead(node);

}else{

NodenewNode=newNode();

newNode.key=key;

newNode.value=value;

cache.put(key,newNode);

addToHead(newNode);

if(cache.size()capacity){

NodetoRemove=tail.prev;

removeNode(toRemove);

cache.remove(toRemove.key);

}

}

}

privatevoidmoveToHead(Nodenode){

removeNode(node);

addToHead(node);

}

privatevoidaddToHead(Nodenode){

node.prev=head;

node.next=head.next;

head.next.prev=node;

head.next=node;

}

privatevoidremoveNode(Nodenode){

node.prev.next=node.next;

node.next.prev=node.prev;

}

}

解析:使用双向链表+哈希表实现。哈希表存储键到节点的映射,链表维护访问顺序。get时将节点移到头部,put时如果键已存在则更新值并移动到头部,如果超出容量则删除尾部节点。

题目3(算法设计)

给定一个包含n个整数的数组,设计一个算法找出数组中所有和为特定值的三元组。要求不重复的三元组,且三元组按升序排列。

java

publicListListIntegerthreeSum(int[]nums){

ListListIntegerres

文档评论(0)

1亿VIP精品文档

相关文档