剑指Offer - 包含min函数的栈
实现思路:运用辅助栈B,每当push进新元素i进栈时,如果B为空或者i小于等于B的栈顶元素,则i同时push进B。
class MinStack {
private Stack<Integer> A, B;
/** initialize your data structure here. */
public MinStack() {
A = new Stack<Integer> ();
B = new Stack<Integer> ();
}
public void push(int x) {
A.push(x);
if (B.empty() || x <= B.peek()) {
B.push(x);
}
}
public void pop() {
if (A.pop().equals(B.peek())) {
B.pop();
}
}
public int top() {
return A.peek();
}
public int min() {
if (!B.empty()) {
return B.peek();
}
return -1;
}
}
计算机网络
端口 IP 域名 MAC Address
端口: 16bits
IP: 32bits
域名: 不定长度
MAC Address: 48bits
PAP and CHAP
两种验证协议都用于验证PPP会话。
PAP密码验证协议(Password Authentication Protocol):PAP 的工作方式类似于标准登录程序,远程系统使用静态用户名和密码组合对自身进行身份验证,密码可以通过已建立的加密隧道以提高安全性,但 PAP 会受到许多攻击,由于信息是静态的,很容易被密码猜测和窥探。
CHAP质询握手验证协议(Challenge Handshake Authentication Protocol): CHAP采用更复杂、更安全的身份验证方法,它通过生成随机字符串为每个身份验证创建一个唯一的质询短语。该质询短语使用单向散列函数与设备主机名相结合,通过此过程,CHAP 可以不通过网络发送静态机密信息的方式进行身份验证。