T136 只出现一次的数字

桌桌 2022-8-12 212 8/12

题目描述:

T136 只出现一次的数字

思路:出现两次的数,二进制位上对应的位也出现两次1和0,类似于按位异或,将所有数都异或操作后得到最后的数。

代码如下:

class Solution:
   def singleNumber(self, nums: List[int]) -> int:
       for i in range(1,len(nums)):
           nums[0] = nums[0]^nums[i]
       return nums[0]

结果如下:

T136 只出现一次的数字

- THE END -

桌桌

8月16日01:07

最后修改:2022年8月16日
0

非特殊说明,本博所有文章均为博主原创。

共有 7 条评论

  1. adult dating

    Guys just made a web-page for me, look at the link: Tell me your recommendations. Thanks. Prince Trevett

  2. adult dating

    I like it when individuals come together and share views. Great blog, keep it up. Malcolm Rugg

  3. Anna94 wants to trade nude pics with you

    Ich wollte einfach einen netten Gruss hinterlassen. Bin gerade auf eure Homepage gestossen. Blake Toh

  4. Loveme

    Ahaa, its pleasant conversation about this paragraph here at this webpage, I have read all that, so at this time me also commenting at this place. Milton Basehore

  5. adult dating

    Plus accounts via subscription their legitimate owner without any risk. Rudolf Buquet

  6. Looking for sex tonight in your area

    Way cool! Some extremely valid points! I appreciate you writing this post plus the rest of the site is really good. Edgar Laskowitz

  7. bahis oyna

    Every when inside a even though we opt for blogs that we read. Listed below would be the newest web pages that we decide on. Vito Marinaccio