Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 12, 2023
1 parent 9bf9c58 commit a2e8742
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/

type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}

func deleteNode(root *TreeNode, key int) *TreeNode {
if root == nil {
return nil
}
if root.Val > key {
root.Left = deleteNode(root.Left, key)
return root
}
if root.Val < key {
root.Right = deleteNode(root.Right, key)
return root
}
if root.Left == nil {
return root.Right
}
if root.Right == nil {
return root.Left
}
node := root.Right
for node.Left != nil {
node = node.Left
}
node.Left = root.Left
root = root.Right
return root
}

func main() {}

0 comments on commit a2e8742

Please sign in to comment.