From 987c0bc36fad90f9583ba9c29762aa25a3e2167d Mon Sep 17 00:00:00 2001 From: Yiyang Kang Date: Sun, 8 Feb 2026 15:19:01 +0900 Subject: [PATCH] stash 1 --- solutions/1/q110/solution.go | 36 ++++++++++++++++++++++++++++++++++ solutions/16/q1653/solution.go | 18 +++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 solutions/1/q110/solution.go create mode 100644 solutions/16/q1653/solution.go diff --git a/solutions/1/q110/solution.go b/solutions/1/q110/solution.go new file mode 100644 index 0000000..94b73e1 --- /dev/null +++ b/solutions/1/q110/solution.go @@ -0,0 +1,36 @@ +package q110 + +type TreeNode struct { + Val int + Left *TreeNode + Right *TreeNode +} + +func abs(a int) int { + if a < 0 { + return -a + } + return a +} + +func isBalancedInternal(node *TreeNode, lvl int) (bool, int) { + if node == nil { + return true, lvl + } + + lBal, lDpth := isBalancedInternal(node.Left, lvl+1) + rBal, rDpth := isBalancedInternal(node.Right, lvl+1) + dpth := max(lDpth, rDpth) + + if !lBal || !rBal || abs(lDpth-rDpth) > 1 { + return false, dpth + } + return true, dpth +} + +func isBalanced(root *TreeNode) bool { + ret, _ := isBalancedInternal(root, 0) + return ret +} + +var _ = isBalanced diff --git a/solutions/16/q1653/solution.go b/solutions/16/q1653/solution.go new file mode 100644 index 0000000..5ccfeca --- /dev/null +++ b/solutions/16/q1653/solution.go @@ -0,0 +1,18 @@ +package q1653 + +func minimumDeletions(s string) int { + bestA, bestB := 0, 0 + + for i := range len(s) { + switch s[i] { + case 'a': + bestB++ + case 'b': + bestA, bestB = bestA+1, min(bestA, bestB) + } + } + + return min(bestA, bestB) +} + +var _ = minimumDeletions