aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2023-09-05 20:31:26 +0300
committerValentin Popov <valentin@popov.link>2023-09-05 20:31:26 +0300
commit4aa0999c8694661e8201bc8675943699b8971e4e (patch)
tree0378ce45af763f04906e285db4a97e848ca35947
parent2f67f65aeb40760d042c4feb882e8f907588cc1c (diff)
downloadleetcode-4aa0999c8694661e8201bc8675943699b8971e4e.tar.xz
leetcode-4aa0999c8694661e8201bc8675943699b8971e4e.zip
feat(two-sum): Решение с брутфорсом
-rw-r--r--two-sum/README.md18
1 files changed, 18 insertions, 0 deletions
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<i32>, target: i32) -> Vec<i32> {
+ 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")
+}
+```
+
## Использование хэщ-таблицы
В этом решении используется хэш-таблица.