Skip to content

2024-04-24 v. 5.5.3: added "2331. Evaluate Boolean Binary Tree" #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2315. Count Asterisks | [Link](https://leetcode.com/problems/count-asterisks/) | [Link](./lib/easy/2315_count_asterisks.rb) |
| 2319. Check if Matrix Is X-Matrix | [Link](https://leetcode.com/problems/check-if-matrix-is-x-matrix/) | [Link](./lib/easy/2319_check_if_matrix_is_x_matrix.rb) |
| 2325. Decode the Message | [Link](https://leetcode.com/problems/decode-the-message/) | [Link](./lib/easy/2325_decode_the_message.rb) |
| 2331. Evaluate Boolean Binary Tree | [Link](https://leetcode.com/problems/evaluate-boolean-binary-tree/) | [Link](./lib/easy/2331_evaluate_boolean_binary_tree.rb) |
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '5.5.2'
s.version = '5.5.3'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
Expand Down
17 changes: 17 additions & 0 deletions lib/easy/2331_evaluate_boolean_binary_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# https://leetcode.com/problems/evaluate-boolean-binary-tree/
# @param {TreeNode} root
# @return {Boolean}
def evaluate_tree(root)
case root.val
when 0
false
when 1
true
when 2
evaluate_tree(root.left) || evaluate_tree(root.right)
else
evaluate_tree(root.left) && evaluate_tree(root.right)
end
end
41 changes: 41 additions & 0 deletions test/easy/test_2331_evaluate_boolean_binary_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/2331_evaluate_boolean_binary_tree'
require_relative '../../lib/common/binary_tree'
require 'minitest/autorun'

class EvaluateBooleanBinaryTreeTest < ::Minitest::Test
def test_default
assert(
evaluate_tree(
::TreeNode.new(
2,
::TreeNode.new(1),
::TreeNode.new(
3,
::TreeNode.new(0),
::TreeNode.new(1)
)
)
)
)
assert(
!evaluate_tree(
::TreeNode.new(0)
)
)
end

def test_additional
assert(
!evaluate_tree(
::TreeNode.new(
3,
::TreeNode.new(0),
::TreeNode.new(1)
)
)
)
end
end
Loading