bjwu

今天在leetcode上遇到了 137. Single Number II 这道题:

给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次。找出那个只出现了一次的元素。(Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.)

Note: 你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?(our algorithm should have a linear runtime complexity. Could you implement it without using extra memory?)

Examples:
Input: [0,1,0,1,0,1,99]
Output: 99

刚开始看到这道题时候,我是略微欣喜的,因为脑子里蹦出的想法应该就是用位异或的方法解决。然而事情并没有那么简单。在草稿纸上模糊了快一个小时候,我点开了Discuss,进入了投票数最高的回答:

这一点开不得了,我的表情是这样的

相关文章:

  • 2021-06-18
  • 2022-01-19
  • 2019-09-05
  • 2020-04-29
  • 2021-09-10
  • 2020-06-11
  • 2021-06-01
  • 2018-03-07
猜你喜欢
  • 2021-10-07
  • 2018-10-22
  • 2021-09-11
  • 2021-04-21
  • 2021-10-09
  • 2020-03-10
  • 2019-12-25
相关资源
相似解决方案