Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Coding Interview
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmytro Bogatov
Coding Interview
Commits
4b1394c5
Commit
4b1394c5
authored
Aug 16, 2020
by
Dmytro Bogatov
Browse files
Options
Downloads
Patches
Plain Diff
Add Lonely Integer.
parent
b318683f
Branches
master
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/hacker-rank/LonelyInteger.cs
+28
-0
28 additions, 0 deletions
src/hacker-rank/LonelyInteger.cs
test/hacker-rank/LonelyInteger.cs
+14
-0
14 additions, 0 deletions
test/hacker-rank/LonelyInteger.cs
with
42 additions
and
0 deletions
src/hacker-rank/LonelyInteger.cs
0 → 100644
+
28
−
0
View file @
4b1394c5
namespace
CodingInterview.HackerRank
{
/// <summary>
/// You will be given an array of integers.
/// All of the integers except one occur twice.
/// That one is unique in the array.
///
/// Given an array of integers, find and print the unique element.
///
/// For example, a = [1, 2, 3, 4, 3, 2, 1], the unique element is 4.
/// </summary>
public
class
LonelyInteger
{
/// <summary>
/// Finds the unique element
/// </summary>
/// <param name="a">An array of integers where each integer occurs twice except one, which occurs once</param>
/// <returns>The integer which occurs once</returns>
public
long
Solve
(
int
[]
a
)
{
for
(
var
i
=
1
;
i
<
a
.
Length
;
i
++)
{
a
[
0
]
=
a
[
0
]
^
a
[
i
];
}
return
a
[
0
];
}
}
}
This diff is collapsed.
Click to expand it.
test/hacker-rank/LonelyInteger.cs
0 → 100644
+
14
−
0
View file @
4b1394c5
using
Xunit
;
namespace
CodingInterview.Tests.HackerRank
{
public
class
LonelyInteger
{
[
Fact
]
public
void
TestCases
()
{
// From Hacker Rank
Assert
.
Equal
(
4
,
new
CodingInterview
.
HackerRank
.
LonelyInteger
().
Solve
(
new
int
[]
{
1
,
2
,
3
,
4
,
3
,
2
,
1
}));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment