From 8f8033e53de5a58e992fc14d708c65d7a9be10d6 Mon Sep 17 00:00:00 2001 From: Bartekr100 Date: Thu, 13 Aug 2026 20:26:53 +0200 Subject: [PATCH] Implement function to find maximum integer value in vector --- homework/max-of-vector/maxOfVector.hpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/homework/max-of-vector/maxOfVector.hpp b/homework/max-of-vector/maxOfVector.hpp index f82fb2a1..2d5ebe38 100644 --- a/homework/max-of-vector/maxOfVector.hpp +++ b/homework/max-of-vector/maxOfVector.hpp @@ -1,8 +1,18 @@ #pragma once -#include +#include // better will be exception #include int maxOfVector(const std::vector& vec) { - // TODO: Implement me :) - return {}; + if (vec.empty()) { + return std::numeric_limits::min(); + } + + int max = vec[0]; + for (auto const el : vec) { + if (max < el) { + max = el; + } + } + + return max; }