Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
jutem committed Sep 13, 2020
1 parent 2a25ab2 commit 4d6cde5
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/com/jutem/cases/java8/lambda/ToListCollector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.jutem.cases.java8.lambda;

import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;

/**
* @author [email protected]
* @create 2019-09-28
*/
public class ToListCollector implements Collector{
/**
* @return
*/
@Override
public Supplier supplier() {
return null;
}

@Override
public BiConsumer accumulator() {
return null;
}

@Override
public BinaryOperator combiner() {
return null;
}

@Override
public Function finisher() {
return Function.identity();
}

@Override
public Set<Characteristics> characteristics() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.jutem.cases.leetcode;

/**
* @author [email protected]
* @create 2020-09-13
*/
public class DeleteNodeInALinkedList {
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}

public class ListNode {
int val;
ListNode next;

ListNode(int x) {
val = x;
}
}


}
66 changes: 66 additions & 0 deletions src/main/java/com/jutem/cases/leetcode/TwoSum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.jutem.cases.leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class TwoSum {
public static void main(String[] args) {
twoSum(new int[]{3,2,4}, 6);
}

public static int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
Integer index = map.get(nums[i]);
if(index == null || i > index) {
map.put(nums[i], i);
}
}

for (int i = 0; i < nums.length; i++) {
int least = target - nums[i];
Integer index = map.get(least);
if(index != null && i != index) {
return new int[]{i, index};
}
}
return null;
}

private int[] firstSolution(int[] nums, int target) {
int[] cal = Arrays.copyOf(nums, nums.length);
Arrays.sort(cal);
for(int head = 0, tail = nums.length - 1; head != tail;) {
int sum = cal[head] + cal[tail];
if(sum == target) {
return new int[]{indexFirst(nums, cal[head]), indexLast(nums, cal[tail])};
}
if(sum > target) {
tail --;
} else {
head ++;
}
}
return null;
}

private int indexLast(int[] nums, int num) {
for(int i = nums.length - 1; i >= 0; i --) {
if(nums[i] == num) {
return i;
}
}
return 0;
}

private int indexFirst(int[] nums, int num) {
for(int i = 0; i < nums.length; i ++) {
if(nums[i] == num) {
return i;
}
}
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MyBeanPostProcess implements BeanPostProcessor{

Expand All @@ -16,4 +19,5 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}

}

0 comments on commit 4d6cde5

Please sign in to comment.