字符串去除前导”0”

  1. String str = "0000000152638382";
  2. String newStr = str.replaceAll("^(0+)", "");

按照绝对值进行排序数组

  1. int[] arr = IntStream.of(arr).boxed().sorted((o1, o2) -> Math.abs(o2) - Math.abs(o1)).mapToInt(Integer::intValue).toArray();
  1. int[] arr = {-9 , -18, -2 ,1,3,5};
  2. Integer[] ints = new Integer[arr.length];
  3. int x = 0;
  4. for (Integer i: arr) {
  5. ints[x++] = i;
  6. }
  7. Arrays.sort(ints,((o1,o2)->Math.abs(o1)-Math.abs(o2)));
  8. System.out.println(Arrays.toString(ints));

链表快慢指针找中点

  1. ListNode fast = head;
  2. ListNode dummy = new ListNode();
  3. dummy.next = head;
  4. ListNode slow = dummy;
  5. while(fast != null && fast.next != null){
  6. slow = slow.next;
  7. fast = fast.next.next;
  8. }
  9. ListNode newHead = slow.next;
  10. slow.next = null;

判断异位词的技巧

hashmap的eauals比较 key—-character value—-character的出现次数 为0的时候需要删除

数组复制 【原始数组,原始索引,目的数组,目的索引,复制长度】

  1. System.arraycopy(arr,0,ints,1,arr.length);