class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
stack = []
for i in nums:
if i not in stack:
stack.append(i)
else:
stack.pop(stack.index(i))
print(stack[0])
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
stack = []
for i in nums:
if i not in stack:
stack.append(i)
else:
stack.pop(stack.index(i))
print(stack[0])

本文介绍了一种使用栈数据结构的方法来找出列表中只出现一次的数字。通过遍历列表并利用栈来跟踪未配对的元素,该算法能够有效地找到目标数字。
919

被折叠的 条评论
为什么被折叠?



