OneTime

2019-03-27 15 words 1 min read

给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。 找出那个只出现了一次的元素。举个例子:

输入: [2,2,1]

输出: 1

return 2*sum(set(nums))-sum(nums)

( 2+1 )*2 - ( 2+2+1 )这样就求出只出现一次的数了,原理就是让出现一次的数也出现两次,然后再减去原来的数组和



Tags: algorithm

Related Articles:


author

Authored By WUHAOTIAN

A gentleman should always strive to improve himself

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it