labuladong / basic-challenge

200 stars 22 forks source link

已结束 #357

Closed labuladong closed 1 year ago

labuladong commented 1 year ago

本期打卡已结算完成。报名最新一期的打卡活动 点这里

DannyT70 commented 1 year ago

https://leetcode.cn/problems/delete-node-in-a-bst/solution/bst1-by-sleepy-shawffi-qj58/

KarlZhu-SE commented 1 year ago

https://leetcode.com/problems/delete-node-in-a-bst/solutions/3916913/delete-node-in-a-bst/

alyssasuper3 commented 1 year ago

https://leetcode.cn/problems/validate-binary-search-tree/solutions/2391268/yan-zheng-er-cha-sou-suo-shu-by-alyssasu-76l4/

Sadwy commented 1 year ago

LC700. https://leetcode.com/problems/search-in-a-binary-search-tree/solutions/3917115/topic/

AstrKing commented 1 year ago

700:https://leetcode.cn/problems/search-in-a-binary-search-tree/solutions/2070407/zai-bst-zhong-sou-suo-yuan-su-by-aktrkin-s2ju/

imzhuting commented 1 year ago

https://leetcode.cn/problems/validate-binary-search-tree/solutions/2391483/yan-zheng-bst-by-emilia-8-obq2/

Xiaolin8991 commented 1 year ago

https://leetcode.cn/problems/delete-node-in-a-bst/solutions/2391541/python3-by-xiao-lin-mz-t5v9/

cs-gavin-huang commented 1 year ago

https://leetcode.com/problems/insert-into-a-binary-search-tree/solutions/3918203/insert-into-a-binary-search-tree/

tonyzhu163 commented 1 year ago
# Aug 16

# LC 230 Kth smallest element in BST

# Just do a traversal and return from arr

class Solution:
    def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
        return self.traverse(root)[k-1]

    def traverse(self, r):
        return self.traverse(r.left) + [r.val] + self.traverse(r.right) if r else []

# LC 700

# Search in a BST
# recusive solution is straightforward

class Solution:
    def searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
        if not root:
            return None

        if root.val == val:
            return root
        elif root.val < val:
            return self.searchBST(root.right, val)
        elif root.val > val:
            return self.searchBST(root.left, val)
ElaineZhou-moon commented 1 year ago

https://leetcode.com/problems/validate-binary-search-tree/solutions/3918634/validate-binary-search-tree/

YilinYan0 commented 1 year ago

https://leetcode.com/problems/search-in-a-binary-search-tree/post-solution/?submissionId=1023148200