随笔分类 - 算法
摘要:package practice01; //在数组里找到唯一出现奇数次的数 public class demo10 { public static int oddNum(int[] arr){ int a=0; for (int i=0;i<arr.length;i++){ a^=arr[i]; /
阅读全文
摘要:package practice01; //在不借助额外变量的情况下,两个数交换 public class demo09 { public static void main(String[] args) { int a=12; int b=89; System.out.println(a); Sys
阅读全文
摘要:public static DoubleNode reverseLinklist(DoubleNode head){ DoubleNode pre=null; //p引用(指针)指向null DoubleNode next=null; while (head!=null){ next=head.ne
阅读全文
摘要:public static Node reverseLinklist(Node head){ Node pre=null; //pre引用(指针)指向null Node next=null; while (head!=null){ next=head.next; //next指针指向head.nex
阅读全文
摘要:在有序数组里,找满足>=value的最左位置 package practice01; //二分法(在有序数组里,找满足>=value的最左位置) public class demo05 { public static int nearestIndex(int[] sortedArr,int num)
阅读全文
摘要:在有序数组里,是否存在某个数 package practice01; import java.util.Arrays; //二分法(在有序数组里,是否存在某个数) public class demo04 { public static boolean existNum(int[] sortedArr
阅读全文
摘要:对数组进行选择排序 package practice01; import java.util.Arrays; public class demo02 { public static void swap(int i,int j,int[] arr){ int temp=arr[i]; arr[i]=a
阅读全文
摘要:对数组进行插入排序 package practice01; import java.util.Arrays; public class demo03 { public static void swap(int i,int j,int[] arr){ int temp=arr[i]; arr[i]=a
阅读全文