Number of lintcode.82 tickets, and lintcode.82

Source: Internet
Author: User
Tags lintcode

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;    }};

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.