2026年苏宁物流工程师面试指南及答案.docxVIP

  • 0
  • 0
  • 约5.87千字
  • 约 17页
  • 2026-02-06 发布于福建
  • 举报

2026年苏宁物流工程师面试指南及答案.docx

第PAGE页共NUMPAGES页

2026年苏宁物流工程师面试指南及答案

一、编程能力测试(共5题,每题10分,总分50分)

1.题目:

请实现一个函数,输入一个整数数组,返回其中重复次数最多的元素及其出现次数。例如,输入`[1,2,2,3,3,3]`,输出`3,3`。

答案:

python

defmost_frequent(nums):

count={}

max_count=0

max_num=None

fornuminnums:

ifnumincount:

count[num]+=1

else:

count[num]=1

ifcount[num]max_count:

max_count=count[num]

max_num=num

returnmax_num,max_count

解析:

-使用字典统计每个元素的出现次数。

-遍历数组时更新最大出现次数及其对应的元素。

-时间复杂度O(n),空间复杂度O(n)。

2.题目:

编写一个函数,将一个字符串中的所有大写字母转换为小写字母,其他字符保持不变。例如,输入`HelloWorld`,输出`helloworld`。

答案:

python

defto_lowercase(s):

returns.lower()

解析:

-利用Python内置的`lower()`方法可直接转换。

-其他语言(如Java)可使用`Character.toLowerCase()`处理单个字符。

3.题目:

给定一个链表,反转其节点并返回新链表的头节点。例如,输入`1-2-3`,输出`3-2-1`。

答案:

python

classListNode:

def__init__(self,val=0,next=None):

self.val=val

self.next=next

defreverse_list(head):

prev=None

current=head

whilecurrent:

next_node=current.next

current.next=prev

prev=current

current=next_node

returnprev

解析:

-使用三指针法(prev,current,next_node)逐个反转节点。

-时间复杂度O(n),空间复杂度O(1)。

4.题目:

实现一个简单的LRU(LeastRecentlyUsed)缓存,支持`get`和`put`操作。缓存容量为3,输入`[get(1),put(2,1),get(2),put(3,2),get(4),get(1),get(3)]`,输出`[None,None,1,None,-1,-1,2]`。

答案:

python

fromcollectionsimportOrderedDict

classLRUCache:

def__init__(self,capacity:int):

self.cache=OrderedDict()

self.capacity=capacity

defget(self,key:int)-int:

ifkeynotinself.cache:

return-1

self.cache.move_to_end(key)

returnself.cache[key]

defput(self,key:int,value:int)-None:

ifkeyinself.cache:

self.cache.move_to_end(key)

self.cache[key]=value

iflen(self.cache)self.capacity:

self.cache.popitem(last=False)

解析:

-使用`OrderedDict`维护访问顺序,`move_to_end`实现最近使用置前。

-超出容量时删除最久未使用的元素。

5.题目:

编写一个函数,输入一个字符串,判断是否是有效的括号组合,如输入`()`返回`True`,`()[]{}`返回`True`,`(]`返回`False`。

答案:

python

defisValid(s:str)-bool:

stack=[]

mapping={):(,]:[,}:{}

forcharins:

ifcharinmapping.values():

stack.append(char

文档评论(0)

1亿VIP精品文档

相关文档