
算法
情人节也放假
这个作者很懒,什么都没留下…
展开
-
二分法查找
public static int search(int[] arr, int key) { int start = 0; int end = arr.length - 1; while (start <= end) { int middle = (start + end) / 2; if (key < arr[m原创 2017-04-09 13:46:39 · 264 阅读 · 0 评论 -
数组中只有一个数出现一次,其他数都出现两次,如何找出只出现一次的那个
参考:http://blog.youkuaiyun.com/cxming007/article/details/23738643public static Integer findOnlyNum1(int[] array){ int result = 0; for(int i = 0 ;i<array.length;i++){ result^=array[i];原创 2017-04-09 13:41:42 · 2576 阅读 · 0 评论 -
一次循环查找字符串中第一个不重复的字节
public static char getChar(String text){ char c =0xff; for(int index =0;index <text.length();index ++){ c =text.charAt(index); if(text.indexOf(c) ==text.lastIndexO原创 2017-04-09 13:36:17 · 410 阅读 · 0 评论 -
链表反转
一、遍历反转public static Node reverse2(Node head) { if (head == null) return head; Node pre = head;// 上一结点 Node cur = head.getNext();// 当前结点 Node tmp;//原创 2017-04-09 13:23:14 · 208 阅读 · 0 评论 -
快排
public void quicksort(int[] v, int left, int right) { if (left < right) { int key = v[left]; int low = left; int high = right; while (low < high)原创 2017-04-07 12:34:07 · 357 阅读 · 0 评论 -
求交集
题目示例:已知两顺序整数集合,求交集原创 2017-03-15 16:59:52 · 337 阅读 · 0 评论 -
约瑟夫环
题目示例:17个人围一桌,轮番报数,报到3的退出,知道桌上只留下1人原创 2017-03-15 16:55:51 · 249 阅读 · 0 评论