small update to LeetCode

This commit is contained in:
cediackermann 2026-06-13 00:03:36 +02:00
parent 160eb549e0
commit b71f6978f1
No known key found for this signature in database

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] {
@ -47,13 +47,20 @@ enum LeetCode {
} }
} }
public class TreeNode { public class TreeNode {
public var val: Int public var val: Int
public var left: TreeNode? public var left: TreeNode?
public var right: TreeNode? public var right: TreeNode?
public init() { self.val = 0; self.left = nil; self.right = nil; } public init() {
public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; } 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?) { public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {
self.val = val self.val = val
self.left = left self.left = left