国际化安全
一面
项目
用到的中间件
基础知识
更新数据库,刷新缓存,通知下游,怎么保持一致性
futuretask
代码
反转链表
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
class Node {
int val;
Node next;
}
public Node reverse(Node head) {
Node prev = null;
Node cur = head;
while (cur != null) {
Node next = cur.next;
cur.next = prev;
prev = cur;
cur = next;
}
return prev;
}
void main() {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
Node head = new Node();
head.val = 1;
Node head1 = new Node();
head1.val = 2;
Node head2 = new Node();
head2.val = 3;
head.next = head1;
head1.next = head2;
Node ans = reverse(head);
for (Node p = ans; p != null; p = p.next) {
System.out.println(p.val);
}
}
用本地IDE写的,不知道IDEA试用期有多久,一会我搞个盗版装上吧。
挂
配送引擎
一面
项目
稳定性保障
代码
数据流取中位数,用两个优先队列实现。
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
PriorityQueue<Integer> qMin = new PriorityQueue<>(),
qMax = new PriorityQueue<>((o1, o2) -> o2 - o1);
void main() {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
int[] a = {10,9,8,7,6,5,4,3,2,1};
for (int i = 0; i < a.length; i++) {
add(a[i]);
System.out.println(getMid());
}
}
void add(int n) {
qMax.offer(n);
qMin.offer(qMax.poll());
if (qMin.size() > qMax.size()) {
qMax.offer(qMin.poll());
}
}
double getMid() {
if (qMax.isEmpty()) {
return 0;
}
if (qMax.size() > qMin.size()) {
return qMax.peek();
}
return (qMax.peek() + qMin.peek()) / 2.0;
}
问题
优先队列的底层实现
秒杀系统如何保证库存一致性