面试常用算法
willlu10
这个作者很懒,什么都没留下…
展开
-
Java实现布隆过滤器
一、介绍1.描述标识阶段1.定义一个位的数组2.使用多个hash函数计算hash值并取模3.将每个hash函数的取模的结果所对应的标志位置位1过滤阶段1.使用多个hash函数计算要查询数据的hash值并取模2.在位数组中寻找,多个值对应的多个为是否全是1,如果有一个不是1就说明不存在该值2.使用场景解决缓存穿透问题、网页黑名单过滤、垃圾邮件过滤等3.布隆过滤器的误差因为布隆过滤器的自身特点,可能会存在误差。当布隆过滤器的返回值为f...原创 2020-06-08 12:25:15 · 684 阅读 · 0 评论 -
求n个数字的前K个数或者求中位数
中位数public class median { private boolean bOdd;//是否奇偶数 private int kv;//k值 private double medium; int partition(double a[], int low, int high) { double tmp = a[low]; ...原创 2018-09-25 21:41:51 · 372 阅读 · 0 评论 -
KMP
KMPpublic class KMP { public static int kmp(String str, String dest,int[] next){//str文本串 dest 模式串 for(int i = 0, j = 0; i < str.length(); i++){ while(j > 0 &...原创 2018-09-25 21:43:29 · 114 阅读 · 0 评论 -
Manacher算法
代码链接:https://www.jianshu.com/p/494d7603cac4解析 :https://blog.csdn.net/zzkksunboy/article/details/72600679代码如下:public class Manacher { public static String longestPalindrome(String string...转载 2018-10-06 09:30:53 · 151 阅读 · 0 评论 -
回文数
public class isPalindrome { public static boolean isPalindrome(int x) { if (x<0 || (x!=0 && x%10==0)) return false; int rev = 0; while (x>rev){ ...原创 2018-10-06 11:55:28 · 155 阅读 · 0 评论 -
两数之和
import java.util.HashMap;public class twoSum { public static int[] twoSum(int[] nums, int target) { HashMap<Integer,Integer> m = new HashMap(); int res[] = new int[2]; ...原创 2018-10-06 11:56:28 · 146 阅读 · 0 评论 -
约瑟夫问题
public class Josephs { static class Node{ Node next; int data; public Node(int data){ this.data=data; } } public static int josephs(Node head,i...原创 2018-10-06 11:57:13 · 2124 阅读 · 0 评论 -
斐波那契
public static long fib(int n){ if (n==0){ return 0; } if (n==1){ return 1; } long fibA=0; long fibB=1; long f...原创 2018-10-06 11:57:56 · 360 阅读 · 0 评论