# Queue [Python] ## 常見屬性 `Queue.qsize()` 返回隊列的大小 `Queue.full()` 如果隊列滿了,返回True,反之False `Queue.empty()` 如果隊列為空,返回True,反之False `Queue.full()` 如果隊列滿了,返回True,反之False `Queue.get()` 取得Queue的第一個item,同時將第一個item剔除隊列 `Queue.put(item)` `Queue.task_done()` 在完成一項工作之後,向任務已經完成的隊列發送一個信號 `Queue.join()` 實際上意味著等到隊列為空,再執行別的操作 ## 應用 * Pascal's Traiangle  ```python= import queue class Solution: def sum(self,nums): l = [] for i in range(len(nums)-1): l.append(nums[i]+nums[i+1]) return l def generate(self, numRows: int) -> List[List[int]]: if numRows == 1: return [[1]] if numRows == 2: return [[1],[1,1]] A = [[1],[1,1]] q = queue.Queue() q.put([1,1]) for i in range(numRows-2): a = q.get() A.append([1]+self.sum(a)+[1]) q.put([1]+self.sum(a)+[1]) return A ``` ###### tags: `Python`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up