前言
兄弟们都会有心仪的offer!!!!!
一、服务器部署应用程序——典型背包问题
二、泛型实现快排
package bigo;
/**
* Created by IntelliJ IDEA.
*
* @Author:
* @Email:
* @Date: 2020/9/10
* @Time: 19:44
* @Version: 1.0
* @Description: Description
*/
import java.util.Arrays;
public class Second {
public static <T extends Comparable<? super T>> void quickSort(T[] arr, int startIndex, int endIndex) {
// 递归结束条件:startIndex大等于endIndex的时候
if (startIndex >= endIndex) {
return;
}
// 得到基准元素位置
int pivotIndex = partition(arr, startIndex, endIndex);
// 根据基准元素,分成两部分递归排序
quickSort(arr, startIndex, pivotIndex - 1);
quickSort(arr, pivotIndex + 1, endIndex);
}
/**
* 分治(双边循环法)
*
* @param arr 待交换的数组
* @param startIndex 起始下标
* @param endIndex 结束下标
*/
private static <T extends Comparable<? super T>> int partition(T[] arr, int startIndex, int endIndex) {
// 取第一个位置的元素作为基准元素(也可以选择随机位置)
T pivot = arr[startIndex];
int left = startIndex;
int right = endIndex;
while (left != right) {
//控制right指针比较并左移
while (left < right && arr[right].compareTo(pivot) <= 0) {
right--;
}
//控制left指针比较并右移
while (left < right && arr[left].compareTo(pivot) > 0) {
left++;
}
//交换left和right指向的元素
if (left < right) {
T p = arr[left];
arr[left] = arr[right];
arr[right] = p;
}
}
//pivot和指针重合点交换
arr[startIndex] = arr[left];
arr[left] = pivot;
return left;
}
public static void main(String[] args) {
Integer[] arr = new Integer[]{1, 22, 34, 43, 33};
quickSort(arr, 0, arr.length - 1);
Double[] arr1 = new Double[]{1.0, 22.0, 34.1, 32.2, 0.7};
quickSort(arr1, 0, arr.length - 1);
System.out.println(Arrays.toString(arr));
System.out.println(Arrays.toString(arr1));
}
}
三、字符串镜面反射
package bigo;
import java.util.ArrayList;
import java.util.List;
/**
* Created by IntelliJ IDEA.
*
* @Author:
* @Email:
* @Date: 2020/9/10
* @Time: 20:11
* @Version: 1.0
* @Description: Description
*/
public class Third {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("AB");
list.add("CD");
System.out.println(new Third().mirror(list));
}
List<String> mirror(List<String> data) {
List<String> ans = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
String temp = data.get(i);
StringBuilder str = new StringBuilder(temp);
ans.add(temp + str.reverse().toString());
}
for (int i = data.size() - 1; i >= 0; i--) {
ans.add(ans.get(i));
}
return ans;
}
}