春节12响
1 |
|
1 |
|
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
- push(x) – Push element x onto stack.
- pop() – Removes the element on top of the stack.
- top() – Get the top element.
- getMin() – Retrieve the minimum element in the stack.
Example:
1
2
3
4
5
6
7
8 MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); --> Returns -3.
minStack.pop();
minStack.top(); --> Returns 0.
minStack.getMin(); --> Returns -2.
- Find Minimum in Rotated Sorted Array II
Hard
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e.,
[0,1,2,4,5,6,7]
might become[4,5,6,7,0,1,2]
).Find the minimum element.
The array may contain duplicates.
Example 1:
1
2 >Input: [1,3,5]
>Output: 1Example 2:
1
2 >Input: [2,2,2,0,1]
>Output: 0Note:
- This is a follow up problem to Find Minimum in Rotated Sorted Array.
- Would allow duplicates affect the run-time complexity? How and why?
???
1 | class Solution { |
- Find Minimum in Rotated Sorted Array
Medium
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e.,
[0,1,2,4,5,6,7]
might become[4,5,6,7,0,1,2]
).Find the minimum element.
You may assume no duplicate exists in the array.
Example 1:
1
2 >Input: [3,4,5,1,2]
>Output: 1Example 2:
1
2 >Input: [4,5,6,7,0,1,2]
>Output: 0
1 | public int findMin(int[] nums) { |
1 | I'm the perfect |
MYSQL事务主要用于保证一串事情要么都成功,要么就回滚,例如付款后,要先写入支付订单表,再个人信息中加入会员权益。这两个操作要么顺序执行成功,要么就回滚
ACID
Atomicity原子性
确保事务内的所有操作都成功完成,否则事务将被中止在故障点,以前的操作将回滚到以前的状态。
Consistency一致性
数据库的修改是一致的
Isolation隔离性
事务是彼此独立的
Durability可靠性
确保事务提交后,结果永久存在
隔离性
隔离性可以防止多个事务并发执行时由于交叉执行而导致数据的不一致。事务隔离分为不同级别,包括
读未提交(Read uncommitted)–不严格
读提交(read committed)
可重复读(repeatable read)–默认级别(避免幻读)
串行化(Serializable)–最严格
1 | update account set money=money+100 where name=’B’; |
当执行第一条语句的时候,事务没有提交,那么来读B的账户钱都多了100块
脏读:读取了另一个事务未提交的数据
情景:多次读同一个数据的时候,这个数据被别人改了,导致结果不一致
幻读和不可重复读一样,读取到了另外一条已经提交的事务,所不同的是它针对的是一批数据的整体
beginTransactionScope(scope, ctx)
1 | const result = await app.mysql.beginTransactionScope(async conn => { |
beginTransaction
1 | const conn = await app.mysql.beginTransaction(); // 初始化事务 |
app.mysql.literals.now
1 select @@tx_isolation;
sudo apt-get update
sudo apt-get install mysql-server
tips本人使用环境ubuntu16
完成安装后,远程连接你会发现2003报错,此时,你对 /etc/mysql/mysql.conf.d/ 文件夹中打开 mysqld.cnf文件修改即可
修改内容将#bind-address = 127.0.0.1 原本没有注释,进行注释
然后你重新远程连接mysql直接变成1130的拒绝访问服务,接下来你要在服务器端登录mysql,执行
进入数据库
mysql -u root -p
切换数据库,
mysql>use mysql;
查看root账号的登录权限,
mysql>select host, user from user;
修改登录权限
mysql>update user set host = ‘%’ where user = ‘root’;
刷新,生效,最后一步,至关重要
mysql>flush privileges;
如果想知道MQ的详细知识可以看我之前的为什么使用消息队列MQ
这里选择最重要的提一下:MQ即消息队列,用来实现程序的异步和解耦,起到消息缓冲,消息分发。通俗来讲就是一个医院(服务器)里面有多个医生(线程或进程),让病人都排队(消息缓冲),有的去A部门,有的去B部门(消息分发)。
RabbitMQ是实现AMQP(高级消息队列协议Advanced Message Queuing Protocol)的消息中间件的一种,Feature就是组件之间解耦,病人排他的队,医生看他的病人,至于怎么排,医生不用操心,至于怎么看病,病人不用操心,都交给MQ
术语:面向消息,队列,路由(点对点/发布订阅),可靠安全