Skip to content

Conversation

nprepaci
Copy link
Contributor

@nprepaci nprepaci commented Oct 3, 2022


func helper(_ root: TreeNode?, _ lastVal: Int) -> Int {
guard let root = root else { return 0 }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make in this way

let i = root.val >= lastVal ? 1 : 0
let left = helper(root.left, max(lastVal, root.val))
let right = helper(root.right, max(lastVal, root.val))
return i + left + right

And using let more profitable for compiler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion. Updated in most recent commit.

@dissesmac dissesmac merged commit fd465a1 into neetcode-gh:main Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants