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
public static String reverseWord(String str){ | |
char[] array = str.toCharArray(); | |
int start=0; | |
int end=array.length-1; | |
reverse(array,0,array.length-1); | |
while (start<=end && array[start]==' ') | |
start++; | |
while (end>=start && array[end] == ' ') | |
end--; |
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
public static void printPairUnsorted(int[] array, int sum){ | |
Set<Integer> s = new HashSet<>(); | |
for(int v:array){ | |
int temp = sum - v; | |
if(s.contains(temp)){ | |
System.out.println(String.format("Pair found %d %d", temp,v)); | |
} | |
s.add(v); | |
} | |
} |
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
public class AssertJ { | |
private AssertJ(){ | |
throw new AssertionError("Invalid Access"); | |
} | |
/** | |
* | |
* @param object which will satisfy following code | |
* <pre> | |
* new Predicate<T>(){ |
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
package org.idey.algo.datastructure.cache; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.SortedMap; | |
import java.util.TreeMap; | |
public class LFUCache<K,V> { | |
private Map<K, Node<K,V>> map = new HashMap<>(); | |
private Map<K, Integer> counts = new HashMap<>(); |
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
package org.idey.algo.datastructure.cache; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class LRUCache<K,V> { | |
private int capacity; | |
private Map<K, Node<K,V>> map = new HashMap<>(); | |
private DoubleLinkedList<K,V> doubleLinkedList=new DoubleLinkedList<>(); |
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
public abstract class AbstractTreeIterator<E> implements Iterator<E> { | |
protected AbstractTreeIterator(TreeNode<E> root){ | |
assert(root!=null); | |
} | |
@Override | |
public void remove() { | |
throw new UnsupportedOperationException("remove is not supported"); | |
} |
OlderNewer