karimhamdanali / codility Goto Github PK
View Code? Open in Web Editor NEWprogramming lessons on codility
programming lessons on codility
When I check the second solution on official codility website
Found some of "Wrong answer"
But unfortunately, they not support us with failed test cases data
If the main has the following code System.out.println(solution(new int[] { 7, 9, 3, 9, 3, 9, 9 }));
an incorrect number is returned by solution2.
The below code for solution2 works well and is of same order:
public static int solution2(int[] A) {
// write your code in Java SE 8
HashSet<Integer> dups = new HashSet<Integer>();
ArrayList<Integer> tmp = new ArrayList<>();
for (int i = 0; i < A.length; i++) {
if (dups.add(A[i])) {
tmp.add(A[i]);
}
else{
tmp.remove(new Integer(A[i]));
}
}
return tmp.get(0);
}
If the main has the following code System.out.println(solution(new int[] { 7, 9, 3, 9, 3, 9, 9 }));
an incorrect number is returned by solution2.
The below code for solution2 works well and is of same order:
public static int solution2(int[] A) {
// write your code in Java SE 8
HashSet<Integer> dups = new HashSet<Integer>();
ArrayList<Integer> tmp = new ArrayList<>();
for (int i = 0; i < A.length; i++) {
if (dups.add(A[i])) {
tmp.add(A[i]);
}
else{
tmp.remove(new Integer(A[i]));
}
}
return tmp.get(0);
}
Came upon this code through google search
codility/src/codility/OddOccurrencesInArray.java
Lines 41 to 46 in 6ddaf5e
If the input array is arranged so that the odd number occurs before the pairs, the output will be the last number did not exist in the set, which may not necessarily be the odd number.
for example, {7, 9, 3, 9, 3, 9, 9} will return 3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.