1.在别的交易所写的业务
有什么难度,是什么架构,如果中间有什么是面试官熟的会问很深的细节,我面的这个面试官估计是做cosmos的,问了cosmos提案的作用和hub的作用
2.btc生态熟吗?ordinals有了解吗?brc20基于什么判断账户余额,要转一笔铭文需要怎么操作。sol生态熟吗?sol的铭文和brc20有什么差别
3.寿司代码,经典反转链表
在牛客上找了题目描述
题目描述
寿司店周年庆,正在举办优惠活动回馈新老用户。
寿司转盘上总共有 n 盘寿司, prices[i] 是第 i 盘寿司的价格。
如果客户选择了第 i 盘寿司, 寿司店免费赠送客户距离第 i 盘寿司最近的下一盘寿司 j ,前提是 prices[j] < prices[i],如果没有满足条件的 i ,则不赠送寿司。
每个价格的寿司都可无限供应。
输入描述
输入的每一个数字代表寿司的价格,每盘寿司的价格之间使用空格分隔,例如:
3 15 6 14
表示:
第 0 盘寿司价格 prices[0] 为 3
第 1 盘寿司价格 prices[1] 为 15
第 2 盘寿司价格 prices[2] 为 6
第 3 盘寿司价格 prices[3] 为 14
寿司的盘数 n 范围为:1 ≤ n ≤ 500
每盘寿司的价格 price 范围为:1≤ price ≤1000
输出描述
输出享受优惠后的一组数据,每个值表示客户端选择第 i 盘寿司实际得到的寿司的总价格,使用空格进行分隔,例如:
3 21 9 17
示例1
输入:
3 15 6 14
输出:
3 21 9 17
作者:code5bug
链接:https://www.nowcoder.com/discuss/622116704721686528
来源:牛客网
要用单调栈,这部分我也不太会。大概模拟了一下这个答案。
import java.util.*;
public class SushiDiscount {
public static int[] calculatePrices(int[] prices) {
int n = prices.length;
int[] result = new int[n];
Deque<Integer> stack = new ArrayDeque<>(); // 存储索引的单调栈
// 遍历每个寿司价格两次(模拟环状效果)
for (int i = 2 * n - 1; i >= 0; i--) {
int currentIndex = i % n;
// 栈中保持单调性,移除不满足条件的元素
while (!stack.isEmpty() && prices[stack.peek()] >= prices[currentIndex]) {
stack.pop();
}
// 如果栈非空,找到最近的较低价格的索引
if (!stack.isEmpty()) {
result[currentIndex] = prices[currentIndex] + prices[stack.peek()];
} else {
result[currentIndex] = prices[currentIndex]; // 没有符合条件的,价格保持不变
}
// 将当前索引压入栈
stack.push(currentIndex);
}
return result;
}
public static void main(String[] args) {
int[] prices = {3, 15, 6, 14};
int[] result = calculatePrices(prices);
System.out.println(Arrays.toString(result)); // 输出结果
}
}
0 1 2 3
3, 15, 6, 14
0 1 2 3 4 5 6 7
3, 15, 6, 14, 3, 15, 6, 14
res[3]=14
3进(14)
3出()
res[2]=6
2进(6)
res[1]=21
1进(6,15)
1出(6)
2出()
res[0]=3
0进(3)
res[3]=17
....
如果寿司不循环
import java.util.*;
public class SushiDiscount {
public static int[] calculatePrices(int[] prices) {
int n = prices.length;
int[] result = new int[n];
Deque<Integer> stack = new ArrayDeque<>(); // 存储索引的单调栈
// 遍历每个寿司价格一次
for (int i = n; i >= 0; i--) {
int currentIndex = i;
// 栈中保持单调性,移除不满足条件的元素
while (!stack.isEmpty() && prices[stack.peek()] >= prices[currentIndex]) {
stack.pop();
}
// 如果栈非空,找到最近的较低价格的索引
if (!stack.isEmpty()) {
result[currentIndex] = prices[currentIndex] + prices[stack.peek()];
} else {
result[currentIndex] = prices[currentIndex]; // 没有符合条件的,价格保持不变
}
// 将当前索引压入栈
stack.push(currentIndex);
}
return result;
}
public static void main(String[] args) {
int[] prices = {3, 15, 6, 14};
int[] result = calculatePrices(prices);
System.out.println(Arrays.toString(result)); // 输出结果
}
}
res[3]=14
3进(14)
3出()
res[2]=6
2进(6)
res[1]=21
1进(6,15)
1出(6)
2出()
res[0]=3
class Solution {
public ListNode reverseList(ListNode head) {
ListNode p = null;
ListNode q = head;
while(q!=null){
ListNode t = q.next;
q.next=p;
p=q;
q=t;
}
return p;
}
}