This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sed -i "s/old/new/" `find . -name '*.txt'` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type BinaryTree struct { | |
head *node | |
} | |
func NewBinaryTree(value int) BinaryTree { | |
return BinaryTree{&node{val: value}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapUtil { | |
/** | |
* 如果map中存在key,将其转化后进行处理 | |
* | |
* @param map | |
* @param key | |
* @param mapper | |
* @param consumer | |
* @param <K> | |
* @param <V> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AopUtils.getTargetClass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.util.Arrays; | |
public class QuickSort { | |
public static void sort(Integer[] arrays, int low, int high) { | |
if (high <= low) { | |
return; | |
} | |
int parationIdx = paration(arrays, low, high); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 将一维数组看做一颗二叉树 父节点和子节点的关系为 Nk~=N2k+1,N2k+2 | |
* 1. 构建堆 | |
* 2. 调整堆 | |
*/ | |
public class HeapSort { | |
public static void main(String[] args) { | |
int[] arr = new int[]{1, 5, 4, 65, 3}; | |
heapSort(arr); | |
for (int n : arr) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description: 参考了 https://www.jianshu.com/p/da312eee4ac4 | |
* @author: alonwang | |
* @create: 2019-07-19 15:54 | |
**/ | |
public class SpuriousWakeUp { | |
private final Object lock = new Object(); | |
private int product = 0; | |
//如果没有产品,在lock对象上等待唤醒,如果有产品,消费. | |
private Runnable consumer = () -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.alonwang.util; | |
import com.google.common.collect.Range; | |
import java.time.LocalDate; | |
import java.time.LocalDateTime; | |
import java.time.LocalTime; | |
import java.time.ZoneId; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int numberOfLeadingZeros(int i) { | |
// HD, Count leading 0's | |
if (i <= 0) | |
return i == 0 ? 32 : 0; | |
int n = 31; | |
if (i >= 1 << 16) { n -= 16; i >>>= 16; } | |
if (i >= 1 << 8) { n -= 8; i >>>= 8; } | |
if (i >= 1 << 4) { n -= 4; i >>>= 4; } | |
if (i >= 1 << 2) { n -= 2; i >>>= 2; } | |
return n - (i >>> 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
简单的词法分析器演示 | |
number: [0-9]+ | |
identifier: [a-zA-Z_] | |
*/ | |
/* | |
0 start | |
1 identifer |