This commit is contained in:
krahets
2026-03-29 05:06:58 +08:00
parent 37523d4ceb
commit 967293c421
51 changed files with 288 additions and 5073 deletions
@@ -228,13 +228,7 @@ comments: true
=== "Ruby"
```ruby title="two_sum.rb"
=begin
File: two_sum.rb
Created Time: 2024-04-09
Author: Blue Bean (lonnnnnnner@gmail.com)
=end
# ## Метод 1: полный перебор ###
### Метод 1: полный перебор ###
def two_sum_brute_force(nums, target)
# Два вложенных цикла, временная сложность O(n^2)
for i in 0...(nums.length - 1)
@@ -527,25 +521,7 @@ comments: true
=== "Ruby"
```ruby title="two_sum.rb"
=begin
File: two_sum.rb
Created Time: 2024-04-09
Author: Blue Bean (lonnnnnnner@gmail.com)
=end
# ## Метод 1: полный перебор ###
def two_sum_brute_force(nums, target)
# Два вложенных цикла, временная сложность O(n^2)
for i in 0...(nums.length - 1)
for j in (i + 1)...nums.length
return [i, j] if nums[i] + nums[j] == target
end
end
[]
end
# ## Метод 2: вспомогательная хеш-таблица ###
### Метод 2: вспомогательная хеш-таблица ###
def two_sum_hash_table(nums, target)
# Вспомогательная хеш-таблица, пространственная сложность O(n)
dic = {}