parent
4305177015
commit
fca8239636
@ -1,5 +1,28 @@
|
|||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
public class Hello {
|
public class Hello {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
|
||||||
|
String username = System.getenv("USERNAME");
|
||||||
|
System.out.println(username);
|
||||||
|
Hello hello = ac.getBean(Hello.class);
|
||||||
|
System.out.println(hello);
|
||||||
|
String a = ac.getEnvironment().getProperty("a");
|
||||||
|
System.out.println(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MyBeanFactoryPostProcess implements BeanFactoryPostProcessor{
|
||||||
|
@Override
|
||||||
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||||
|
BeanDefinition hello = beanFactory.getBeanDefinition("Hello");
|
||||||
|
// hello.set
|
||||||
System.out.println(12);
|
System.out.println(12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.context.annotation.ImportResource;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@PropertySource(value = {"a.properties"})
|
||||||
|
public class A {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ImportResource;
|
||||||
|
|
||||||
|
//@ImportResource(locations = {"bean.xml"})
|
||||||
|
public class B {
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
a=12
|
@ -0,0 +1,47 @@
|
|||||||
|
package zuolaos.jichuban;
|
||||||
|
|
||||||
|
public class Code11_异或运算 {
|
||||||
|
|
||||||
|
|
||||||
|
//某个数出现奇数次 其他出现偶数次
|
||||||
|
public static void m1(int[] arr) {
|
||||||
|
int ans = 0;
|
||||||
|
for (int i = 0; i < arr.length; i++) {
|
||||||
|
ans ^= arr[i];
|
||||||
|
}
|
||||||
|
System.out.println(ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
//某两个数出现奇数次 其他出现偶数次
|
||||||
|
public static void m3(int[] arr) {
|
||||||
|
int ans = 0;
|
||||||
|
for (int num : arr) {
|
||||||
|
ans ^= num;
|
||||||
|
}
|
||||||
|
int rightOne = ans & (-ans);
|
||||||
|
int ans2 = 0;
|
||||||
|
for (int num : arr) {
|
||||||
|
if ((num & rightOne) != 0) {
|
||||||
|
ans2 ^= num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(ans2);
|
||||||
|
System.out.println(ans ^ ans2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//某个数出现了K次 其他数出现了M次
|
||||||
|
public static void m2(int[] arr, int k, int m) {
|
||||||
|
int[] bits = new int[32];
|
||||||
|
for (int num : arr) {
|
||||||
|
for (int i = 0; i < 32; i++) {
|
||||||
|
bits[i] += (num >> i) & 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int ans = 0;
|
||||||
|
for (int i = 0; i < bits.length; i++) {
|
||||||
|
if (bits[i] % m != 0) {
|
||||||
|
ans |= (1 << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package zuolaos.jichuban;
|
||||||
|
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
public class Code11_栈和队列 {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TowStacktToQueue{
|
||||||
|
|
||||||
|
|
||||||
|
Stack<Integer> push=new Stack<>();
|
||||||
|
Stack<Integer> poll=new Stack<>();
|
||||||
|
|
||||||
|
public void offer(){
|
||||||
|
TreeMap<Object, Object> objectObjectTreeMap = new TreeMap<>();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package zuolaos.jichuban;
|
||||||
|
|
||||||
|
public class Code12_归并排序进阶 {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//找到子数组累加和 在lower upper范围内
|
||||||
|
class FindZiShuZuSum {
|
||||||
|
public static int start(int[] arr, int lower, int upper) {
|
||||||
|
int[] help = new int[arr.length];
|
||||||
|
help[0] = arr[0];
|
||||||
|
for (int i = 1; i < arr.length; i++) {
|
||||||
|
help[i] = help[i - 1] + arr[i];
|
||||||
|
}
|
||||||
|
return process(help, 0, help.length - 1, lower, upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int process(int[] help, int L, int R, int lower, int upper) {
|
||||||
|
if (L == R) {
|
||||||
|
if (help[L] >= lower && help[L] <= upper) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int M = L + ((R - L) >> 1);
|
||||||
|
int left = process(help, L, M, lower, upper);
|
||||||
|
int right = process(help, M + 1, R, lower, upper);
|
||||||
|
int merge = merge(help, L, M, R, lower, upper);
|
||||||
|
return left + right + merge;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int merge(int[] help, int L, int M, int R, int lower, int upper) {
|
||||||
|
int windowL = L;
|
||||||
|
int windowR = L;
|
||||||
|
int ans = 0;
|
||||||
|
for (int i = M + 1; i <= R; i++) {
|
||||||
|
int max = help[i] - lower;
|
||||||
|
int min = help[i] - upper;
|
||||||
|
//找到第一个满足条件的左窗口
|
||||||
|
while (windowL <= M && help[windowL] < min) {
|
||||||
|
windowL++;
|
||||||
|
}
|
||||||
|
//找到第一个不满足条件的右窗口
|
||||||
|
while (windowR <= M && help[windowR] <= max) {
|
||||||
|
windowR++;
|
||||||
|
}
|
||||||
|
ans += windowR - windowL;
|
||||||
|
}
|
||||||
|
int[] temp = new int[R - L + 1];
|
||||||
|
int indexL = L;
|
||||||
|
int indexR = M+1;
|
||||||
|
int indexCur = 0;
|
||||||
|
while (indexL <= M && indexR <= R) {
|
||||||
|
temp[indexCur++] = help[indexL] <= help[indexR] ? help[indexL++] : help[indexR++];
|
||||||
|
}
|
||||||
|
while (indexL <= M) {
|
||||||
|
temp[indexCur++] = help[indexL++];
|
||||||
|
}
|
||||||
|
while (indexR <= R) {
|
||||||
|
temp[indexCur++] = help[indexR++];
|
||||||
|
}
|
||||||
|
for (int i = 0; i < temp.length; i++) {
|
||||||
|
help[i + L] = temp[i];
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] arr={-2,2,1};
|
||||||
|
int lower=0;
|
||||||
|
int upper=2;
|
||||||
|
System.out.println(start(arr,lower,upper));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,207 @@
|
|||||||
|
package zuolaos.jichuban;
|
||||||
|
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
|
||||||
|
public class Code13_堆排序 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
MyMinHeap myMaxHeap = new MyMinHeap(10);
|
||||||
|
myMaxHeap.push(5);
|
||||||
|
myMaxHeap.push(1);
|
||||||
|
myMaxHeap.push(5);
|
||||||
|
myMaxHeap.push(9);
|
||||||
|
myMaxHeap.push(105);
|
||||||
|
System.out.println(myMaxHeap.pop());
|
||||||
|
System.out.println(myMaxHeap.pop());
|
||||||
|
System.out.println(myMaxHeap.pop());
|
||||||
|
System.out.println(myMaxHeap.pop());
|
||||||
|
System.out.println(myMaxHeap.pop());
|
||||||
|
|
||||||
|
int arr[] = {8, 1, 2, 3, 4, 5, 6, 70};
|
||||||
|
MyMinHeap myMinHeap = new MyMinHeap(arr);
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
System.out.println(myMinHeap.pop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MaxMoveK {
|
||||||
|
public void process(int[] arr, int k) {
|
||||||
|
//小顶堆
|
||||||
|
PriorityQueue<Integer> heap = new PriorityQueue<>();
|
||||||
|
int index = 0;
|
||||||
|
for (; index < Math.min(k, arr.length - 1); index++) {
|
||||||
|
heap.add(arr[index]);
|
||||||
|
}
|
||||||
|
int arrIndex=0;
|
||||||
|
for (; index < arr.length; index++) {
|
||||||
|
heap.add(arr[index]);
|
||||||
|
arr[arrIndex++]=heap.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!heap.isEmpty()){
|
||||||
|
arr[arrIndex++]=heap.poll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyMinHeap {
|
||||||
|
private int[] heap;
|
||||||
|
private final int limit;
|
||||||
|
private int heapSize;
|
||||||
|
|
||||||
|
public MyMinHeap(int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
heap = new int[limit];
|
||||||
|
heapSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyMinHeap(int[] heap) {
|
||||||
|
this.heap = heap;
|
||||||
|
this.limit = heap.length;
|
||||||
|
this.heapSize = heap.length;
|
||||||
|
for (int i = heapSize - 1; i >= 0; i--) {
|
||||||
|
helpify(heap, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return this.heapSize == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFull() {
|
||||||
|
return this.heapSize == this.limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void push(int value) {
|
||||||
|
if (isFull()) {
|
||||||
|
throw new RuntimeException("heap is full");
|
||||||
|
}
|
||||||
|
heap[heapSize] = value;
|
||||||
|
helpinsert(heap, heapSize++);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int pop() {
|
||||||
|
int ans = heap[0];
|
||||||
|
swap(heap, 0, --heapSize);
|
||||||
|
helpify(heap, 0);
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
//新加起来的元素在index的位置上
|
||||||
|
public void helpinsert(int[] arr, int index) {
|
||||||
|
while (arr[(index - 1) / 2] > arr[index]) {
|
||||||
|
//交换
|
||||||
|
swap(arr, index, (index - 1) / 2);
|
||||||
|
index = (index - 1) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//在index位置不断的下沉
|
||||||
|
public void helpify(int[] arr, int index) {
|
||||||
|
int left = 2 * index + 1;
|
||||||
|
while (left < heapSize) {
|
||||||
|
int least = left + 1 < heapSize && arr[left + 1] < arr[left] ? left + 1 : left;
|
||||||
|
least = arr[index] > arr[least] ? least : index;
|
||||||
|
if (least == index) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
swap(arr, index, least);
|
||||||
|
index = least;
|
||||||
|
left = 2 * index + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void swap(int[] arr, int i, int j) {
|
||||||
|
if (i == j) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
arr[i] = arr[i] ^ arr[j];
|
||||||
|
arr[j] = arr[i] ^ arr[j];
|
||||||
|
arr[i] = arr[i] ^ arr[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MyMaxHeap {
|
||||||
|
private int[] heap;
|
||||||
|
private final int limit;
|
||||||
|
private int heapSize;
|
||||||
|
|
||||||
|
public MyMaxHeap(int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
heap = new int[limit];
|
||||||
|
heapSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return this.heapSize == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFull() {
|
||||||
|
return this.heapSize == this.limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void push(int value) {
|
||||||
|
if (isFull()) {
|
||||||
|
throw new RuntimeException("heap is full");
|
||||||
|
}
|
||||||
|
heap[heapSize] = value;
|
||||||
|
helpinsert(heap, heapSize++);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int pop() {
|
||||||
|
int ans = heap[0];
|
||||||
|
swap(heap, 0, --heapSize);
|
||||||
|
helpify(heap, 0);
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
//新加起来的元素在index的位置上
|
||||||
|
public void helpinsert(int[] arr, int index) {
|
||||||
|
while (arr[(index - 1) / 2] < arr[index]) {
|
||||||
|
//交换
|
||||||
|
swap(arr, index, (index - 1) / 2);
|
||||||
|
index = (index - 1) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//在index位置不断的下沉
|
||||||
|
public void helpify(int[] arr, int index) {
|
||||||
|
int left = 2 * index + 1;
|
||||||
|
while (left < heapSize) {
|
||||||
|
int large = left + 1 < heapSize && arr[left + 1] > arr[left] ? left + 1 : left;
|
||||||
|
large = arr[index] < arr[large] ? large : index;
|
||||||
|
if (large == index) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
swap(arr, index, large);
|
||||||
|
index = large;
|
||||||
|
left = 2 * index + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void swap(int[] arr, int i, int j) {
|
||||||
|
if (i == j) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
arr[i] = arr[i] ^ arr[j];
|
||||||
|
arr[j] = arr[i] ^ arr[j];
|
||||||
|
arr[i] = arr[i] ^ arr[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
|||||||
|
package zuolaos.jichuban;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Code14_前缀树 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Trie trie = new Trie();
|
||||||
|
|
||||||
|
trie.insert("abc");
|
||||||
|
trie.insert("abcd");
|
||||||
|
trie.insert("ab");
|
||||||
|
trie.insert("ac");
|
||||||
|
trie.insert("ae");
|
||||||
|
trie.insert("ae");
|
||||||
|
trie.insert("ae");
|
||||||
|
System.out.println(trie.search("ae"));
|
||||||
|
System.out.println(trie.search("abc"));
|
||||||
|
trie.delete("ae");
|
||||||
|
System.out.println(trie.search("ae"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Trie {
|
||||||
|
private class Node {
|
||||||
|
int pass;
|
||||||
|
int end;
|
||||||
|
private Map<Integer, Node> nextNodes;
|
||||||
|
|
||||||
|
public Node(){
|
||||||
|
pass=0;
|
||||||
|
end=0;
|
||||||
|
nextNodes=new HashMap<Integer, Node>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Node root;
|
||||||
|
|
||||||
|
public Trie() {
|
||||||
|
root = new Node();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(String word) {
|
||||||
|
if (word == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char[] chars = word.toCharArray();
|
||||||
|
Node temp = root;
|
||||||
|
temp.pass++;
|
||||||
|
int index = 0;
|
||||||
|
for (int i = 0; i < chars.length; i++) {
|
||||||
|
index = chars[i];
|
||||||
|
if (!temp.nextNodes.containsKey(index)) {
|
||||||
|
temp.nextNodes.put(index, new Node());
|
||||||
|
}
|
||||||
|
temp = temp.nextNodes.get(index);
|
||||||
|
temp.pass++;
|
||||||
|
}
|
||||||
|
temp.end++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void delete(String word) {
|
||||||
|
if (search(word) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char[] chars = word.toCharArray();
|
||||||
|
Node temp = root;
|
||||||
|
temp.pass--;
|
||||||
|
int index = 0;
|
||||||
|
for (int i = 0; i < chars.length; i++) {
|
||||||
|
index = chars[i];
|
||||||
|
if(--temp.nextNodes.get(index).pass==0){
|
||||||
|
temp.nextNodes.remove(index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
temp=temp.nextNodes.get(index);
|
||||||
|
}
|
||||||
|
temp.end--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int search(String word) {
|
||||||
|
if (word == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
char[] chars = word.toCharArray();
|
||||||
|
Node temp = root;
|
||||||
|
int index = 0;
|
||||||
|
for (int i = 0; i < chars.length; i++) {
|
||||||
|
index = chars[i];
|
||||||
|
if (!temp.nextNodes.containsKey(index)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
temp = temp.nextNodes.get(index);
|
||||||
|
}
|
||||||
|
return temp.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package zuolaos.jichuban;
|
||||||
|
|
||||||
|
public class Code15_基数排序 {
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
a=12
|
Loading…
Reference in new issue