## 題解 ### inorder traversal decrease k value ```python= # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: # inorder traversal node ,stack = root, [] while node or stack: while node: # 走到最左子樹 stack.append(node) node = node.left node = stack.pop() k -= 1 if k == 0: return node.val node = node.right ```
×
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