sherxon / algods Goto Github PK
View Code? Open in Web Editor NEWImplementation of Algorithms and Data Structures, Problems and Solutions
Home Page: http://sherxon.com
License: MIT License
Implementation of Algorithms and Data Structures, Problems and Solutions
Home Page: http://sherxon.com
License: MIT License
if array is {8,7,6,7,4},result is wrong
It will be almost twice as fast, using half as much space, if you only sieve over odd numbers.
https://github.com/sherxon/AlgoDS/blob/master/src/interviewquestions/easy/ContainsDuplicate.java#L17:
for (int i : nums) {
if (!set.add(-2 * i)) return true;
}
Why multiply by -2?
See https://repl.it/HBRv/0: new int[] {2147483646, -2}
contains duplicates.
In your solution you have used priority queue to fetch second minimum node. Wouldn't it be much more efficient if you simply returned leftmost element in the right subtree of the root ?
hope provide unit test for these solutions
thanks :)
hi I like your code for ReverseInteger. Why do you use the Math.abs()? Here is another approach with less code:
public int reverse(int x) {
int rev = 0;
while(x != 0){
rev = rev*10 + x%10;
x = x/10;
}
return rev;
}
can i see your solution for dealing with duplicates?
Looks like CycleDetection will fail if Graph has multiple component.
It would be really cool to have Bloom Filter.
Hello.
I'm not fluent in Java so I won't implement it by myself, however there is an O(log n)
solution for finding nth Fibonacci number which is based on matrix exponentiation -
[[1 1] [1 0]]^n = [[F_{n+1} F_n] [F_n F_{n-1}]]
This can be done with exponentiation by squaring which is O(log n)
.
Whether or not there is a cycle, this program always returns true after running
` for (Integer neighbor : graph.getNeighbors(start)) {
if(visited.contains(neighbor) && !exited.contains(neighbor)) return true;
if(!visited.contains(neighbor) && dfs(neighbor)) return true;
}`
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.