Number of lintcode.82 tickets, and lintcode.82
Number of orders placed
- Description
- Notes
- Data
- Evaluation
2 * n + 1 digits are given. Each digit except one is displayed twice.
Have you ever encountered this question during a real interview? Yes, which company asked you this question? Airbnb Amazon LinkedIn Cryptic Studios Dropbox Apple Epic Systems TinyCo Yelp Hedvig Zenefits Uber Snapchat Yahoo Microsoft Bloomberg Facebook Google Twitter
Thank you for your feedback.
Example
Given[1, 2, 1, 3, 3], Returns 4
Challenges
Extra space complexity at the constant level during one Traversal
TagGreedy
Related Questions
This question is very good, and it is cleverly solved by bit operations. At first, I thought about multiset and so on. The ^ bit operation is king. It can solve a pile of numbers and find numbers with an odd number.
All numbers ^ themselves are equal to 0, which is the core of this question.
In addition, write down the common usage of ^,
Used as swap, a = a ^ B;
B = B ^;
A = a ^ B;
This formula is equivalent to a = a ^ B ^. Equivalent to a = B;
Flip the number, 1 ^ n.
class Solution {public: /* * @param A: An integer array * @return: An integer */ int singleNumber(vector<int> &A) { // write your code here int ans=0; int s=A.size(); for(int i=0;i<s;i++) { ans^=A[i]; } return ans; }};