最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

合并两个双端队列的最快方法

SEO心得admin45浏览0评论
本文介绍了合并两个双端队列的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否存在一种更快的合并两个双端队列的方法?

Exist a faster way to merge two deques than this?

# a, b are two deques. The maximum length # of a is greater than the current length # of a plus the current length of b while len(b): a.append(b.popleft())

请注意,我对保留输入双端队列不感兴趣,只对尽快合并合并双端感兴趣.

Note that I'm not interested in preserving input deques, I'm only interested in having the merged one as fast as possible.

推荐答案

不需要逐元素追加,只需使用+=:

There's no need for elementwise appending, you can just use +=:

from collections import deque a = deque([1, 2, 3]) b = deque([4, 5, 6]) a += b print(a) deque([1, 2, 3, 4, 5, 6])
发布评论

评论列表(0)

  1. 暂无评论