Skip to content

2025-03-26 v. 9.1.2: added "2221. Find Triangular Sum of an Array" #1001

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
Mar 26, 2025
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 @@ -746,6 +746,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2177. Find Three Consecutive Integers That Sum to a Given Number | [Link](https://leetcode.com/problems/find-three-consecutive-integers-that-sum-to-a-given-number/) | [Link](./lib/medium/2177_find_three_consecutive_integers_that_sum_to_a_given_number.rb) | [Link](./test/medium/test_2177_find_three_consecutive_integers_that_sum_to_a_given_number.rb) |
| 2181. Merge Nodes in Between Zeros | [Link](https://leetcode.com/problems/merge-nodes-in-between-zeros/) | [Link](./lib/medium/2181_merge_nodes_in_between_zeros.rb) | [Link](./test/medium/test_2181_merge_nodes_in_between_zeros.rb) |
| 2196. Create Binary Tree From Descriptions | [Link](https://leetcode.com/problems/create-binary-tree-from-descriptions/) | [Link](./lib/medium/2196_create_binary_tree_from_descriptions.rb) | [Link](./test/medium/test_2196_create_binary_tree_from_descriptions.rb) |
| 2221. Find Triangular Sum of an Array | [Link](https://leetcode.com/problems/find-triangular-sum-of-an-array/) | [Link](./lib/medium/2221_find_triangular_sum_of_an_array.rb) | [Link](./test/medium/test_2221_find_triangular_sum_of_an_array.rb) |
| 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) |
| 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) |
| 2657. Find the Prefix Common Array of Two Arrays | [Link](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/) | [Link](./lib/medium/2657_find_the_prefix_common_array_of_two_arrays.rb) | [Link](./test/medium/test_2657_find_the_prefix_common_array_of_two_arrays.rb) |
Expand Down
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 = '9.1.1'
s.version = '9.1.2'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
18 changes: 18 additions & 0 deletions lib/medium/2221_find_triangular_sum_of_an_array.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# https://leetcode.com/problems/find-triangular-sum-of-an-array/
# @param {Integer[]} nums
# @return {Integer}
def triangular_sum(nums)
count = nums.size

until count == 1
(0...(count - 1)).each do |i|
nums[i] = (nums[i] + nums[i + 1]) % 10
end

count -= 1
end

nums.first
end
25 changes: 25 additions & 0 deletions test/medium/test_2221_find_triangular_sum_of_an_array.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/medium/2221_find_triangular_sum_of_an_array'
require 'minitest/autorun'

class FindTriangularSumOfAnArrayTest < ::Minitest::Test
def test_default_one
assert_equal(
8,
triangular_sum(
[1, 2, 3, 4, 5]
)
)
end

def test_default_two
assert_equal(
5,
triangular_sum(
[5]
)
)
end
end