mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Fine tune.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
* Author: S-N-O-R-L-A-X (snorlax.xu@outlook.com)
|
||||
*/
|
||||
|
||||
|
||||
/* Driver Code */
|
||||
/* 初始化队列 */
|
||||
// JavaScript 没有内置的队列,可以把 Array 当作队列来使用
|
||||
// 注意:由于是数组,所以 shift() 的时间复杂度是 O(n)
|
||||
@@ -20,7 +22,7 @@ queue.push(4);
|
||||
const peek = queue[0];
|
||||
|
||||
/* 元素出队 */
|
||||
// O(n)
|
||||
// shift() 方法的时间复杂度为 O(n)
|
||||
const poll = queue.shift();
|
||||
|
||||
/* 获取队列的长度 */
|
||||
|
||||
Reference in New Issue
Block a user