"Leetcode" 136.Excel Sheet Column Title

Source: Internet
Author: User

Given an array of integers, every element appears twice except for one. Find the single one.

Note:
Your algorithm should has a linear runtime complexity. Could you implement it without using extra memory?

Hide TagsHash Table Bit manipulationThe title requirement is a specific condition, and only one numeric value appears once
1 classSolution {2  Public:3     intSinglenumber (intA[],intN) {4         intx;5          for(size_t i=0; i<n; ++i)6X ^=A[i];7         returnx;8     }9};
Status:AcceptedRuntime:18 mssubmitted:3 months, 3 weeks ago but I think the x here is not initialized, find C++primer version fifth, P40 page has the corresponding default initialization definition: "If a variable of a built-in type is not being displayed initialized, Its value is determined by the location of the definition. Variables defined outside of any function body are initialized to 0. Built-in type variables defined inside the function body will not be initialized. "The main function is also a function, so the global variable is initialized to 0, is the member function in the class initialized to 0?" This is not yet confirmed. So I changed the next
1 intSinglenumber (intA[],intN) {2     if(N <1)3         returnNULL;4     intx = a[0];5      for(size_t i=1; i<n; ++i)6X ^=A[i];7     returnx;8}

At this time unexpectedly does not have AC, prompt compile Error

Line 19:no matching function for call to ' Solution::singlenumber (std::vector<int>&) '

"Leetcode" 136.Excel Sheet Column Title

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.