GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode-1/algorithms/cpp/singleNumber/singleNumber.cpp at master · mtangm/leetcode-1

Expand file tree

/

singleNumber.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
32 lines (29 loc) · 920 Bytes
/

singleNumber.cpp

Copy path

File metadata and controls

32 lines (29 loc) · 920 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Source : https://oj.leetcode.com/problems/single-number/
// Author : Hao Chen
// Date : 2014-06-17
/**********************************************************************************
*
* Given an array of integers, every element appears twice except for one. Find that single one.
*
* Note:
* Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
*
*
**********************************************************************************/
#include <stdio.h>
// This is classical interview question
// As we know, the same number XOR together will be 0,
// So, XOR all of numbers, the result is the number which only appears once.
int singleNumber(int A[], int n) {
int s = 0;
for(int i=0; i<n; i++){
s = s^A[i];
}
return s;
}
int main()
{
int a[]={1,1,2,2,3};
printf("%d\n", singleNumber(a,5));
return 0;
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.