Created
October 17, 2018 18:59
-
-
Save yokolet/ddaadd36d93de7311985041c1acf3f1b to your computer and use it in GitHub Desktop.
Single Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Description: | |
| Given a non-empty array of integers, every element appears twice except for one. Find | |
| that single one. The algorithm should have a linear runtime complexity. | |
| Examples: | |
| Input: [2,2,1] | |
| Output: 1 | |
| Input: [4,1,2,1,2] | |
| Output: 4 | |
| """ | |
| def singleNumber(nums): | |
| """ | |
| :type nums: List[int] | |
| :rtype: int | |
| """ | |
| v = 0 | |
| for num in nums: | |
| v ^= num | |
| return v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment