一、力扣
1、有效的括号字符串
678. 有效的括号字符串


class Solution {
public boolean checkValidString(String s) {
int minCount = 0;
int maxCount = 0;
for (int i = 0; i < s.length(); i++) {
char temp = s.charAt(i);
if (temp == '(') {
minCount++;
maxCount++;
} else if (temp == ')') {
minCount--;
maxCount--;
} else {
minCount--;
maxCount++;
}
minCount = Math.max(minCount, 0);
if (maxCount < 0) {
return false;
}
}
return minCount == 0;
}
}
2、柱状图中最大的矩形
84. 柱状图中最大的矩形

class Solution {
public int largestRectangleArea(int[] heights) {
int n = heights.length;
int[] left = new int[n];
int[] right = new int[n];
ArrayDeque<Integer> queue = new ArrayDeque<>();
for (int i = 0; i < n; i++) {
while (!queue.isEmpty() && heights[queue.peek()] >= heights[i]) {
queue.pop();
}
left[i] = -1;
if (!queue.isEmpty()) {
left[i] = queue.peek();
}
queue.push(i);
}
queue = new ArrayDeque<>();
for (int i = n - 1; i >= 0; i--) {
while (!queue.isEmpty() && heights[queue.peek()] >= heights[i]) {
queue.pop();
}
right[i] = n;
if (!queue.isEmpty()) {
right[i] = queue.peek();
}
queue.push(i);
}
int res = 0;
for (int i = 0; i < n; i++) {
res = Math.max(res, heights[i] * (right[i] - left[i] - 1));
}
return res;
}
}
3、课程表
207. 课程表

class Solution {
List<Integer>[] path;
int[] color;
public boolean canFinish(int numCourses, int[][] prerequisites) {
path = new List[numCourses];
color = new int[numCourses];
Arrays.setAll(path, e -> new ArrayList<>());
for (var e : prerequisites) {
path[e[1]].add(e[0]);
}
for (int i = 0; i < numCourses; i++) {
if (color[i] == 0 && !dfs(i)) {
return false;
}
}
return true;
}
public boolean dfs(int x) {
color[x] = 1;
for (int nex : path[x]) {
if (color[nex] == 1 || (color[nex] == 0 && !dfs(nex))) {
return false;
}
}
color[x] = 2;
return true;
}
}
4、24 点游戏
679. 24 点游戏


class Solution {
private static final double TARGET = 24;
private static final double EPISLON = 1e-6;
public boolean judgePoint24(int[] cards) {
return helper(new double[]{ cards[0], cards[1], cards[2], cards[3] });
}
private boolean helper(double[] nums) {
if (nums.length == 1) return Math.abs(nums[0] - TARGET) < EPISLON;
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
double[] next = new double[nums.length - 1];
for (int k = 0, pos = 0; k < nums.length; k++) {
if (k != i && k != j) {
next[pos++] = nums[k];
}
}
for (double num : calculate(nums[i], nums[j])) {
next[next.length - 1] = num;
if (helper(next)) return true;
}
}
}
return false;
}
private List<Double> calculate(double a, double b) {
List<Double> list = new ArrayList<>();
list.add(a + b);
list.add(a - b);
list.add(b - a);
list.add(a * b);
if (!(Math.abs(b) < EPISLON)) {
list.add(a / b);
}
if (!(Math.abs(a) < EPISLON)) {
list.add(b / a);
}
return list;
}
}
5、通配符匹配
44. 通配符匹配

class Solution {
public boolean isMatch(String s, String p) {
int m = s.length(), n = p.length();
boolean[][] dp = new boolean[m + 1][n + 1];
dp[0][0] = true;
for (int i = 1; i <= n; i++) {
if (p.charAt(i - 1) == '*') {
dp[0][i] = true;
} else {
break;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (p.charAt(j) == '?') {
dp[i + 1][j + 1] = dp[i][j];
} else if (p.charAt(j) == '*') {
dp[i + 1][j + 1] = dp[i + 1][j] || dp[i][j + 1];
} else {
if (p.charAt(j) == s.charAt(i)) {
dp[i + 1][j + 1] = dp[i][j];
}
}
}
}
return dp[m][n];
}
}
二、语雀-Netty
1、为什么Netty适合做网络编程?
✅为什么Netty适合做网络编程?

2、Netty性能好的原因是什么?
Netty性能好的原因是什么?

3、什么是零拷贝?
✅什么是零拷贝?

1. DMA

2. mmap


4、Netty的零拷贝是怎么实现的?
✅Netty的零拷贝是怎么实现的?


5、能不能说一说Netty的无锁化设计?
✅能不能说一说Netty的无锁化设计?

6、Netty的线程模型是怎么样的?
✅Netty的线程模型是怎么样的?

1. 单Reactor单线程模型

2. 单Reactor多线程模型

3. 主从Reactor模型

7、Netty如何解决TCP粘包、拆包的问题的?
✅Netty如何解决TCP粘包、拆包的问题的?

8、Netty的Buffer为什么好用
✅Netty的Buffer为什么好用


9、说说 Netty 的对象池技术?
✅说说 Netty 的对象池技术?


10、Netty有哪些序列化协议?
✅Netty有哪些序列化协议?

三、语雀-微服务
1、分布式和微服务的区别是什么?
✅分布式和微服务的区别是什么?

2、什么是微服务架构?优势?特点?
✅什么是微服务架构?优势?特点?

3、限流、降级、熔断有什么区别?
✅限流、降级、熔断有什么区别?
1. 限流

2. 降级

3. 熔断
