• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
zyytxdy
博客园    首页    新随笔    联系   管理    订阅  订阅
只出现一次的数

#自己做的
num=input([int]) 不明白为什么统计次数这个方法是行不通的
for i in num:
a=num.count()
if a>=2:
num.remove(a)
continue
else:
print(num)



#答案

class Solution:
def singleNumber(self, nums: List[int]) -> int: 后来仔细一看才发现原来还可以用异或来做
for i in range(1, len(nums)):
nums[0] ^= nums[i]
return nums[0]
posted on 2022-11-08 22:26  紫苏。。  阅读(27)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3