23 劍指offer第二十三題(python)

2021-09-25 09:10:46 字數 513 閱讀 9584

問題:

輸入乙個整數陣列,判斷該陣列是不是某二叉搜尋樹的後序遍歷的結果。如果是則輸出yes,否則輸出no。假設輸入的陣列的任意兩個數字都互不相同。

**:# -*- coding:utf-8 -*-

class solution:

def verifysquenceofbst(self, sequence):

# write code here

if not sequence:

return false

if len(sequence)<=2:

return true

flag='leftree'

for i in range(len(sequence)-1):

if flag=='leftree' and sequence[i]>sequence[-1]:

flag='rightree'

else:

if flag=='rightree' and sequence[i]占用記憶體:5852k

《劍指offer》第二十三題(鍊錶中環的入口結點)

面試題23 鍊錶中環的入口結點 題目 乙個鍊錶中包含環,如何找出環的入口結點?例如,在圖3.8的鍊錶中,環的入口結點是結點3。include include list.h listnode meetingnode listnode phead 魯棒一 先確定有沒有環,有的話先求得環中任意乙個節點 r...

第二十三天

1 使用 koa 搭建伺服器 const koa require koa 路由請求 context ctx 上下文 包含req和res ctx.body hello koa2 2 如何配置 koa 路由 const koa require koa 建立路由物件 const router requir...

劍指offer第二十三題二叉搜尋樹的後序遍歷

放在前面 寫了兩天 最後寫 了!輸入乙個整數陣列,判斷該陣列是不是某二叉搜尋樹的後序遍歷的結果。如果是則輸出yes,否則輸出no。假設輸入的陣列的任意兩個數字都互不相同。package test class solution public boolean verifysquenceofbst int...