From 4aa0999c8694661e8201bc8675943699b8971e4e Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 5 Sep 2023 21:31:26 +0400 Subject: =?UTF-8?q?feat(two-sum):=20=D0=A0=D0=B5=D1=88=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=20=D0=B1=D1=80=D1=83=D1=82=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D1=81=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/two-sum/README.md b/two-sum/README.md index 28150e9..ef6598b 100644 --- a/two-sum/README.md +++ b/two-sum/README.md @@ -1,5 +1,23 @@ # Two Sum +## Использование брутфорса + +Самое просто решение. Сложность алгоритма `O(n^2)`. + +```rust +pub fn two_sum(nums: Vec, target: i32) -> Vec { + for (i, x) in nums.iter().enumerate() { + for (j, y) in nums.iter().enumerate() { + if i != j && x + y == target { + return vec![i as i32, j as i32]; + } + } + } + + panic!("No solution found") +} +``` + ## Использование хэщ-таблицы В этом решении используется хэш-таблица. -- cgit v1.2.3