Skip to content

Instantly share code, notes, and snippets.

@injust90
Last active November 3, 2022 02:25
Show Gist options
  • Save injust90/c930f8f85c83ab3335d7fc30419a30dc to your computer and use it in GitHub Desktop.
Save injust90/c930f8f85c83ab3335d7fc30419a30dc to your computer and use it in GitHub Desktop.
int lonelyinteger(vector<int> a) {
int result = 0;
// for each element if result is equal to start of line then result is set to that value.
for (int i : a)
{
result = result ^ i;
}
return result;
}
@injust90
Copy link
Author

injust90 commented Nov 3, 2022

Input: [1, 2, 3, 4, 3, 2, 1]
Returns: 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment