xbox1994 / java-interview Goto Github PK
View Code? Open in Web Editor NEW经历BAT面试后总结的【高级Java后台开发面试指南】,纯净干货无废话,针对高频面试点
License: MIT License
经历BAT面试后总结的【高级Java后台开发面试指南】,纯净干货无废话,针对高频面试点
License: MIT License
谢谢楼主
xhs:
https://blog.csdn.net/inrgihc/article/details/119335835
https://leetcode.cn/problems/24-game/description/
zj:
java == equal 区别
trie树
顺时针打印矩形
ali:
socket线程安全?
java锁
zj:
https://blog.51cto.com/u_16213413/7116665
ali:
mvvc
锁、事务、消息队列、一致性算法、限流
问:有个表特别大,字段是姓名、年龄、班级,如果调用select * from table where name = xxx and age = xxx该如何通过建立索引的方式优化查询速度?
答:由于mysql查询每次只能使用一个索引,如果在name、age两列上创建复合索引的话将带来更高的效率。如果我们创建了(name, age)的复合索引,那么其实相当于创建了(name, age)、(name)三个索引,这被称为最佳左前缀特性。因此我们在创建复合索引时应该将最常用作限制条件的列放在最左边,依次递减。其次还要考虑该列的数据离散程度,如果有很多不同的值的话建议放在左边,name的离散程度也大于age。
这里的 (name,age) 索引使用的不是最左前缀原则,而是索引下推
最左前缀原则用于 name like 'A%'
这样的查询,会使用到索引,加速查询
索引下推是指在索引遍历的过程中优先对索引中包含的字段做判断,不满足条件的直接过滤,减少回表次数
redis进程模型,5.0前后区别
RDB、AOF实现原理
redis渐进式rehash原理
hashmap扩容过程
threadlocal原理
其他限流算法
https://leetcode.cn/problems/populating-next-right-pointers-in-each-node/description/
题目:
有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的哪一位?
import java.util.Scanner;
public class Test {
static int n; //从屏幕输入固定的人数n;
static int[] people; //人的数组;
public static void main(String[] args) {
System.out.println("请输入人数n:");
Scanner input = new Scanner(System.in);
n = input.nextInt();
people = new int[n];
//开始非3的数设置报数
selectNoThreeToSet();
//打印结果
printResult();
}
//开始非3的数设置报数
private static void selectNoThreeToSet() {
int notThreeCount = n, num = 1; //不是3的个数,用来作为一个跳出循环的条件,当notThreeCount=1时,跳出循环,代表只剩一个了
for (int i = 0; ; i++) {
if (i == n) //检索不是只遍历一次数组,需要循环遍历,当下标i自加到数组最后时,需要从0开始自加 ,多次遍历
{
i = 0;
}
if (people[i] != 3) { //只有不为3的进行赋值
if (num > 3) //报号的数,循环123,如果大于3即4,重新从1开始
{
num = 1;
}
people[i] = num;
if (num == 3) //当只有报数为3时notThreeCount自减
{
notThreeCount--;
}
num++; //如果一个同学报数成功,下一个需要加1(这里不考虑循环回1)
}
if (notThreeCount == 1) {
break;
}
}
}
//打印结果
private static void printResult() {
int t = 0;
for (int i = 0; i < n; i++) {
System.out.print(people[i] + "\t");
if (people[i] != 3) {
t = i;
}
}
System.out.printf("\n最后剩下的数为原来第%d号的同学\n", t + 1);
}
}
public class Test {
public static int findSurvivor(int n, int m) {
List people = new ArrayList<>();
for (int i = 1; i <= n; i++) {
people.add(i); // 初始化列表,包含1到n的人
}
while (people.size() > 1) {
for (int j = 0; j < m - 1; j++) {
people.add(people.remove(0)); // 移除第0个元素并添加到列表末尾
}
people.remove(0); // 移除第0个元素,即报数到m的人
}
return people.get(0); // 返回最后剩下的那个人的原始编号
}
public static void main(String[] args) {
int n = 10; // 人数
int m = 3; // 报数上限
System.out.println("最后剩下的是原来第 " + findSurvivor(n, m) + " 号的人");
}
}
ThreadLocal
使用ThreadLocal userInfo = new ThreadLocal()的方式,让每个线程内部都会维护一个ThreadLocalMap,里边包含若干了 Entry(K-V 键值对),每次存取都会先的都当前线程,然后得到该线程对象中的Map,然后与Map交互。
此处有错别字
的确问的都是这些,哈哈
如题,反转打印那里写的不对
TreeNode currentLineRightestNode = this;
.....
if (currentNode.value == currentLineRightestNode.value) {
System.out.println();
currentLineRightestNode.value = nextLineRightestNode.value;
}
currentLineRightestNode.value = nextLineRightestNode.value;
这样赋值之后,TreeNode 不就被修改了吗?
数据库主从延迟同步方案、大数据量实时写查如何实现
强一致如何实现
kafka架构、顺序消息如何实现
IM架构如何实现,消息保存在哪里,从哪里拉数据
我不太理解为什么要加上t1.join();t2.join();这两行代码,我不加结果是一样的呀,加了的话意义在哪里呢?
http://118.25.23.115/
https://tech.meituan.com/2014/08/20/innodb-lock.html
https://zhuanlan.zhihu.com/p/67542731
B与B+区别:
压缩链表原理:
在内存中是连续存储的,但是不同于数组,为了节省内存,ziplist的每个元素所占的内存大小可以不同
ziplist将一些必要的偏移量信息记录在了每一个节点里,使之能跳到上一个节点或下一个节点
与跳表应用场景:
当zset满足以下两个条件的时候,使用ziplist:
HashMap rehash过程:
redis数据过期策略:
定时过期:每个设置过期时间的key都需要创建一个定时器,到过期时间就会立即清除
惰性过期:只有当访问一个key时,才会判断该key是否已过期,过期则清除
定期过期:每隔一定的时间,会扫描一定数量的数据库的expires字典中一定数量的key,并清除其中已过期的key
内存淘汰策略:
no-eviction:当内存不足以容纳新写入数据时,新写入操作会报错
allkeys-lru:当内存不足以容纳新写入数据时,在键空间中,移除最近最少使用的key
allkeys-random:当内存不足以容纳新写入数据时,在键空间中,随机移除某个key
volatile-lru:当内存不足以容纳新写入数据时,在设置了过期时间的键空间中,移除最近最少使用的key
volatile-random:当内存不足以容纳新写入数据时,在设置了过期时间的键空间中,随机移除某个key
volatile-ttl:当内存不足以容纳新写入数据时,在设置了过期时间的键空间中,有更早过期时间的key优先移除
多线程交替打印alibaba:
https://blog.csdn.net/CX610602108/article/details/106427979
我自行实现的简单解法:
public class Test {
private int currentI = 0;
private synchronized void printSpace(int inputLength) {
while (true) {
if (currentI == inputLength) {
currentI = 0;
System.out.print(" ");
this.notifyAll();
} else {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private synchronized void printLetter(int i, char c) {
while (true) {
if (i == currentI) {
currentI++;
System.out.print(c);
this.notifyAll();
} else {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private synchronized void print(String input) throws Exception {
Test test = new Test();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
int finalI = i;
Thread tt = new Thread(() -> test.printLetter(finalI, c));
tt.start();
}
Thread space = new Thread(() -> test.printSpace(input.length()));
space.start();
space.join();
}
public static void main(String[] args) throws Exception {
Test test = new Test();
test.print("alibaba");
}
}
/*
二十进制相加
sample
input
1234567890+abcdefghij
99999jjjjj+9999900001
output
bdfi02467j
iiiij00000
*/
项目中的设计模式:状态机
https://www.cnblogs.com/xyzq/p/11090344.html
多叉树中最长的连续序列:
https://gist.github.com/thanlau/34bd056dd0b1662d5fd483e157a27dfb
/**
Definition for a multi tree node.
public class MultiTreeNode {
int val;
List<MultiTreeNode> children;
MultiTreeNode(int x) { val = x; }
}
/
public class Solution {
/*
public int longestConsecutive3(MultiTreeNode root) {
// Write your code here
if (root == null){
return 0;
}
helper(root);
return max;
}
public int[] helper(MultiTreeNode root) {
int up = 0;
int down = 0;
if (root == null){
return new int[]{down, up};
}
for ( MultiTreeNode node : root.children ){
int[] h = helper(node);
if (node.val == root.val + 1){
down = Math.max(down, h[0] + 1);
}
if (node.val + 1 == root.val){
up = Math.max(up, h[1] + 1);
}
}
max = Math.max(max, down + up + 1);
return new int[]{down, up};
}
}
https://crossoverjie.top/%2F2017%2F08%2F11%2Fsbc4%2F
重排链表
count1count*count字段区别
😄 这是一个很不错的 repo。
after cloning the project,
pictures cannot be accessed via local markdown file
在jvm那个章节中 关于破坏双亲委派的链接栗子给的不合理。栗子只是展示了怎么自定义一个类加载器而没有正真意义上去破坏双亲委派模型。不是简单的去重写findCLass就完事了。建议换个好一点的栗子。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.