This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static HashMap<Integer, Integer> lookup = new HashMap<>(); | |
| private static int fib(int n){ | |
| if(lookup.containsKey(n)) | |
| return lookup.get(n); | |
| else{ | |
| if(n <= 1) | |
| lookup.put(n, n); | |
| else{ | |
| int k = (n & 1) == 1? (n+1)/2 : n/2; | |
| if((n&1) == 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.LinkedList; | |
| import java.util.Queue; | |
| public class Traversals { | |
| private ArrayList<Integer> G[]; | |
| private boolean visited[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class BFS{ | |
| private Vector<Integer> distance; | |
| private Vector<Integer> parent; | |
| private Vector<String> colour; | |
| private Vector<Integer> g[]; | |
| private int vertexCount; | |
| private HashSet<Integer> vertices; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Collections; | |
| import java.util.HashSet; | |
| import java.util.Vector; | |
| public class DFS { | |
| private Vector<Integer> discoveredTime; | |
| private Vector<Integer> finishedTime; | |
| private Vector<Integer> parent; | |
| private Vector<String> colour; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Stack; | |
| public class SortStack { | |
| private static Stack<Integer> sortStack(Stack<Integer> stack){ | |
| Stack<Integer> helperStack = new Stack<>(); | |
| while(!stack.isEmpty()){ | |
| int current = stack.pop(); | |
| while(!helperStack.isEmpty() && current < helperStack.peek()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Stack; | |
| public class BalancedParantheses { | |
| private boolean isOpeningSymbol(char a){ | |
| return a == '(' || a == '{' || a == '['; | |
| } | |
| private char getClosingSymbol(char a){ | |
| if(a == '(') return ')'; | |
| if(a == '{') return '}'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def luhn(a): | |
| def get_odd(a): | |
| x = 0 | |
| while a > 0: | |
| s = a % 10 | |
| s = 2*s | |
| if s > 9: | |
| s = (s-1) % 9 + 1 | |
| x += s | |
| a //= 100 |
NewerOlder