📅  最后修改于: 2023-12-03 15:06:21.600000             🧑  作者: Mango
这是一套适用于亚马逊 SDE-1 职位面试的专访题目集合,题目涵盖了算法和数据结构、系统设计、软件工程和计算机科学等多个方面。希望这些题目能够帮助你准备面试,以期获得一份满意的工作。
示例答案:
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
if not head or not head.next:
return head
ret = self.reverseList(head.next)
head.next.next = head
head.next = None
return ret
示例答案:
class Solution:
def isValid(self, s: str) -> bool:
stack = []
for c in s:
if c == '(' or c == '{' or c == '[':
stack.append(c)
elif c == ')' and stack and stack[-1] == '(':
stack.pop()
elif c == '}' and stack and stack[-1] == '{':
stack.pop()
elif c == ']' and stack and stack[-1] == '[':
stack.pop()
else:
return False
return not stack
示例答案:
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
d = {}
for i, num in enumerate(nums):
if target - num in d:
return [d[target - num], i]
d[num] = i
return []
示例答案:
待完善
示例答案:
class LRUCache:
def __init__(self, capacity: int):
self.capacity = capacity
self.cache = {}
self.head = DLinkedNode()
self.tail = DLinkedNode()
self.head.next = self.tail
self.tail.prev = self.head
def get(self, key: int) -> int:
if key not in self.cache:
return -1
node = self.cache[key]
self.move_to_head(node)
return node.value
def put(self, key: int, value: int) -> None:
if key in self.cache:
node = self.cache[key]
node.value = value
self.move_to_head(node)
else:
if len(self.cache) == self.capacity:
removed = self.remove_tail()
del self.cache[removed.key]
node = DLinkedNode(key, value)
self.cache[key] = node
self.add_to_head(node)
def move_to_head(self, node: DLinkedNode) -> None:
self.remove_node(node)
self.add_to_head(node)
def remove_node(self, node: DLinkedNode) -> None:
node.prev.next = node.next
node.next.prev = node.prev
def add_to_head(self, node: DLinkedNode) -> None:
node.prev = self.head
node.next = self.head.next
self.head.next.prev = node
self.head.next = node
def remove_tail(self) -> DLinkedNode:
node = self.tail.prev
self.remove_node(node)
return node
class DLinkedNode:
def __init__(self, key=0, value=0):
self.key = key
self.value = value
self.prev = None
self.next = None
示例答案:
class Timer:
def __init__(self):
self.elapsed_time = 0
self.state = "STOPPED"
self.start_time = None
self.paused_time = None
def start(self):
if self.state == "STOPPED":
self.start_time = time.time()
self.state = "RUNNING"
def stop(self):
if self.state == "RUNNING" or self.state == "PAUSED":
end_time = time.time()
self.elapsed_time += end_time - self.start_time
self.start_time = None
self.paused_time = None
self.state = "STOPPED"
def pause(self):
if self.state == "RUNNING":
self.paused_time = time.time()
self.state = "PAUSED"
def resume(self):
if self.state == "PAUSED":
self.start_time += time.time() - self.paused_time
self.state = "RUNNING"
示例答案:
待完善
示例答案:
待完善
示例答案:
待完善
本套题目集合中,包含了算法和数据结构、系统设计、软件工程和计算机科学等多个方面的题目,对于应聘亚马逊 SDE-1 职位的程序员来说,这些题目都是非常实用的面试题。通过刻意练习这些题目,可以提高自己的编程能力和面试技巧,为自己在面试中取得成功提供帮助。