chore: commit pending changes before monorepo submodule conversion

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
cediackermann 2026-06-10 22:52:49 +02:00
parent 019f20a2c7
commit 2aca9c3df5
No known key found for this signature in database
2 changed files with 43 additions and 4 deletions

View file

@ -14,7 +14,7 @@ enum LeetCode {
} }
static func sortedSquares(_ nums: [Int]) -> [Int] { static func sortedSquares(_ nums: [Int]) -> [Int] {
nums.map { $0 * $0 }.sorted() nums.map { $0 $0 }.sorted()
} }
static func productExceptSelf(_ nums: [Int]) -> [Int] { static func productExceptSelf(_ nums: [Int]) -> [Int] {
@ -24,15 +24,39 @@ enum LeetCode {
var prefix = 1 var prefix = 1
for i in 0..<n { for i in 0..<n {
result[i] = prefix result[i] = prefix
prefix *= nums[i] prefix = nums[i]
} }
var suffix = 1 var suffix = 1
for i in stride(from: n - 1, through: 0, by: -1) { for i in stride(from: n - 1, through: 0, by: -1) {
result[i] *= suffix result[i] = suffix
suffix *= nums[i] suffix = nums[i]
} }
return result return result
} }
static func invertTree(_ root: TreeNode?) -> TreeNode? {
var invertedTree: TreeNode
if root?.left != nil || root?.right != nil {
guard let nodeVal = root?.val else {
}
invertedTree = TreeNode(nodeVal, root?.right, root?.left)
}
return invertedTree
}
}
public class TreeNode {
public var val: Int
public var left: TreeNode?
public var right: TreeNode?
public init() { self.val = 0; self.left = nil; self.right = nil; }
public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }
public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {
self.val = val
self.left = left
self.right = right
}
} }

View file

@ -9,3 +9,18 @@
// print(LeetCode.singleNumber([4, 1, 2, 1, 2])) // print(LeetCode.singleNumber([4, 1, 2, 1, 2]))
// print(LeetCode.containsDuplicate([1, 2, 3, 4])) // print(LeetCode.containsDuplicate([1, 2, 3, 4]))
// print(LeetCode.productExceptSelf([-1, 1, 0, -3, 3])) // print(LeetCode.productExceptSelf([-1, 1, 0, -3, 3]))
let tree = TreeNode(
4,
TreeNode(
2,
TreeNode(1),
TreeNode(3)
),
TreeNode(
7,
TreeNode(6),
TreeNode(9)
)
)
print(LeetCode.invertTree(tree))