Skip to content

Instantly share code, notes, and snippets.

View kehtolaulu's full-sized avatar
🦥

Emilia Garipova kehtolaulu

🦥
View GitHub Profile
public class TrianglePrinter {
public static void main(String[] args) {
printTriangle(5);
}
public static void printTriangle(int h) {
System.out.print(buildTriangle(h));
}
private static String buildTriangle(int h) {
@kehtolaulu
kehtolaulu / BM.java
Created May 19, 2018 17:48
Boyer-Moore algorithm
import java.util.HashMap;
public class BM {
public static void main(String[] args) {
String source = "abcde";
String template = "cd";
System.out.println(getFirstEntry(source, template));
}
public static HashMap<Character, Integer> makeOffsetTable(String pattern) {
@kehtolaulu
kehtolaulu / KMP.java
Created May 19, 2018 17:47
Knuth-Morris-Pratt algorithm
public class KMP {
public static void main(String[] args) {
String string = "abcdefgabd";
String word = "defg";
System.out.println(getFirstEntry(string, word));
}
public static int[] prefixFunction(String s) {
int[] p = new int[s.length()];